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.

7 Years
Discussion Span
Last Post by Mayank23

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>

Edited by Saith: n/a

	Purpose: Have user input lines of code until sentinel value has been found. Output results
	Name: Saith
	Date: 2/4/11

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.

Edited by Saith: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.