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.
// Testing.cpp : string initiated outputs
//
#include "stdafx.h"
#include <string>
#include <iostream>
usingnamespace 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";
}
elseif(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.