I cant find the error in this piece of code could anyone please insight me? I ran the debugging but the errors are un-understandable..
#include \"stdafx.h\"
#in
Should be
if (name == "Bart Simpson")
{
cout << "You have been very naughty" << endl;
}
And you need to include <string>
I assume the bracket in the wrong place is just a problem when pasting the code
if(name == "Bart Simpson")
name will never equal "Bart Simpson", since extracting a string stops when it encounters whitespace; so it would only be "Bart". Perhaps you want to use getline() instead?
Problems:
#includes, which probably caused your initial compiler errors.if statement.The following should work as you expect:
#include "stdafx.h"
#include <iostream>
#include <ostream>
#include <string>
using namespace std;
int main()
{
cout << "Input your name please?" << endl;
string name;
getline(cin, name);
if (name == "Bart Simpson")
{
cout << "You have been very naughty" << endl;
}
return 0;
}
(You need to include string for std::string and std::getline, and ostream for std::endl.)