how can a user be able to type what ever he wants such as " i went to the park...", i tried to do it but with my string variable it only read the first word typed in, such as i in this case.
please help.
how can a user be able to type what ever he wants such as " i went to the park...", i tried to do it but with my string variable it only read the first word typed in, such as i in this case.
please help.
thank you for the reply, i ahve another question to it, how can i get a prargraph or more than one line?
call the function multiple times.
If you are reading the input from a file, you can run a while loop that checks for EOF.
If you are reading from user input, make a sentinel to end the while loop.
while(string_name != "Done"){ // or change the string to whatever you want, "Exit" "Finished", "0"
<some code here>
}
/*
Purpose: Have user input lines of code until sentinel value has been found. Output results
Name: Saith
Date: 2/4/11
*/
#include<iostream>
#include<string>
using namespace std;
int main() {
string line, paragraph; // strings are initialized as empty, no need to assign them.
while(line != "done"){
paragraph += line;
cout << "Enter newest line.\n";
getline(cin, line);
}
cout << paragraph;
return 0;
}
Here is a sample that I just created using user input.
thanks a lot i really appreciate it.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.