a new string class

Hey, this is just a question: Would it be useful to have a new string class ended by the new line \n character?
Not really. If you want to make sure a string can contain no more than one line, you can still use std::string and have it hold no more than one line.
No, I mean a manipulatable string that goes on until you hit enter. spaces are included when you cout<<
Perhaps you're looking for getline instead of a new string class?

http://www.cplusplus.com/reference/string/getline/
Last edited on
in a way, but getline isn't the default application of strings usually cin>> is. I want to , and am making a string class that goes right up until newline is reached. also it will be smaller (sizeof wise) than string.
Doesn't getline do that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

int main()
{
    std::string line;

    std::cout << "Please type a string of characters or words followed by ENTER\n> ";
    std::getline(std::cin, line);

    std::cout << "\n";
    std::cout << line;

    return 0;
}
Please type a string of characters or words followed by ENTER
> This works properly. I swear!

This works properly. I swear!


As for making it smaller, that would cool but isn't only 4 bytes?
Last edited on
I'm not arguing that getline () doesn't do it. im saying cin>> does not. with mine cin>> would. and yes it is only 4 bytes. mine would be 2. also I want to add things like the divide operator. you divide the string by another and it would take all the letters in string 2 and get them out of string 1
I would personally keep the same string class (as the size is not really a problem) but a library of functions to modify strings in different ways would be neat.
sargon94 wrote:
also I want to add things like the divide operator. you divide the string by another and it would take all the letters in string 2 and get them out of string 1

You know, when people complain about operator overloading in C++ that's exactly what they have in mind. Why not just have a properly named member function?
Topic archived. No new replies allowed.