I'm working on an assignment where I have to split up a program into modules of .cpp and .h files, and I'm getting a weird error. In one of my .cpp files, I have the code
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
bool getYesNoResponse()
{
string response;
getline (cin, response);
while (response.size() == 0 ||
(response[0] != 'y' && response[0] != 'Y'
&& response[0] != 'n' && response[0] != 'N'))
{
if (response.size() > 0)
cout << "Please respond 'yes' or 'no'. " << flush;
getline (cin, response);
}
return response[0] == 'y' || response[0] == 'Y';
}
I get the error error: 'string' was not declared in this scope
. I'm not supposed to edit the actual code given to me (we're only supposed to write the includes and defining the functions in the .h files), but I wanted to see if the string problem was a one time thing, so I replaced string
with std::string
in the "string response;
" line, and the problem ceased; except I then got error: 'cin' was not declared in this scope
with the next line. I have my #include
for <string>
, <iostream>
, and <fstream>
, so I'm rather confused as to why it's not working. Any advice on how to fix this without altering my source code would be appreciated!