string issues. simple.

i have a string that will not hold anything past one word. why is this and how to i get it to do so? im using it to simply initiate another output which i know is very un-concise but i dont really mind its just a program for practice. the string in question is string f heres my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

// Testing.cpp : string initiated outputs
//

#include "stdafx.h"
#include <string>
#include <iostream>

using namespace std;
int main ()
{
	string w;
	string f;
	cout << "how are you today\n\n";
	cin >> w;				//round 1

	if(w=="good"){
		cout << "\nIm glad to hear that. what did you do today?\n\n";
	}
	else if(w=="bad"){
		cout << "\nIm sorry to hear that. what happened?\n\n";
	}
	else
		cout << "does not comply";

	cin >> f;				// round 2
	cout << "\nUnfortunately i have never had an experience like that, for i am a sedentary\n being.";
	cout << "\nNot only this, but i am also a being without emotions, who cares what you did today!";
	

	int wait;
	cin >> wait;

	return 0;

}
how are you checking if f has anything in it? What I see is you don't print out f's contents anywhere anywhere. Unless you are watching a debuggers watch window with that variable specifically, you just assuming that doesn't have value.
cin only reads up until the first space or the first end of line, and discards everything else. Read http://www.cplusplus.com/reference/string/getline/ and use something like getline ( cin, f ) to read in the user's entire input. Don't forget to include a using std::getline; if you ever decide to stop using entire std namespace.

Also, try not to mix cin and getline. You might just want to use getline for all of your input needs. Read here: http://www.cplusplus.com/forum/articles/6046/
RIGGHHTTT. stupid me. thanks tyl998
No problem :)
Topic archived. No new replies allowed.