/*Following errors*/
1>C++ Notes and Practice.cpp(37): error C2226: syntax error : unexpected type 'std::string'
1>C++ Notes and Practice.cpp(39): error C2065: 'mystr' : undeclared identifier
1>C++ Notes and Practice.cpp(40): error C2065: 'mystr' : undeclared identifier
cout<<"Hello readers"<<endl;
so I know obviously I have to declare the identifier since i'm using string mystr; but where? I thought the "#include <string>" already declared it? and what is this "std::string"? here is my work...
________________________________________________________________________________
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main(void)
{
system("color e0");
cout<<"Let's play a quick number guessing game!"<<endl;
cout<<"\n\n\n\n\n\n\n\n\n\n\n";
system("Pause");
system("Cls");
int answer;
cout<<"I am thinking of a number between 1 through 25." //Question being asked
<<endl<<"_____________________________________________________"<<endl;
do
{
cin>>answer;
if (answer>24) cout<<"High Number, wrong!"<<endl;
else if (answer<22) cout<<"Low Number, wrong!"<<endl;
else cout<<"Correct! The answer is 23!"<<endl;
while (answer != 23); /*Answer to question*/
}
string mystr;
cout<<"Was that fun or what!, What is your name by the way?"<<endl;
getline (cin, mystr);
cout<<"Nice to meet you "<<mystr<<"."<<endl;
system("pause");
cout<<"My name is Ric"<<endl;
int a, b;
int result;
a = 1990;
b = 2011;
result = a - b;
Try using the c_str() member function to send the string to the cout. It might be trying to tell you that there is no operator<< that takes a std::string as an argument. the string is in the std name space which is why the compiler is telling you std::string. You typed "using name space std" at the top but that just causes less typing for you. It doesn't change that string is within the std name space.