I am trying to make an array of strings in C++. The problem is this that i need the strings to be multiline.
Is this possible in C++? how can we do it?

Recommended Answers

All 4 Replies

This is no such concept as multi-line strings. If you want CR/LF in the string then just append "\n" whereever you want a new line to begin when output

std::string hello = "Hello\nWorld\n";
cout << hello;

by multi-line i mean this concept
getline(cin, quiz, '$');

This will allow the user to enter strings composed of multiple lines. He can continue to enter strings (even if he presses enter) until he presses $.

now i want to make an array which can store this type of strings. Is it again not possible??

you mean something like this?

std::vector<std::string> arr;
std::string line;

while( getline(cin,line) && line[0] != '$')
{
    arr.push_back(line);
}

I hope you realize you can't enter "$1,000.00" with that

yes, i mean this thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.