Reputation: 104
I've just started using C++ like an hour ago and I also just started coding 2 weeks ago, my first project is Visual Novel which I make with engine called Ren'py (A python based engine). I wanna learn how to program with Visual Studio, if anyone can help me I'd be grateful.
This is my code:
#include <iostream>
#include <string>
#include "stdafx.h"
using namespace std;
int main()
{
string a;
cin >> a;
cout << "Nama saya adalah " << a;
return 0;
}
And this is the errors
Severity Code Description Project File Line Suppression State
Error C2146 syntax error: missing ';' before identifier 'a' ConsoleApplication2 c:\users\admin\source\repos\consoleapplication2\consoleapplication2\consoleapplication2.cpp 8
Error C2065 'string': undeclared identifier ConsoleApplication2 c:\users\admin\source\repos\consoleapplication2\consoleapplication2\consoleapplication2.cpp 8
Error C2065 'cout': undeclared identifier ConsoleApplication2 c:\users\admin\source\repos\consoleapplication2\consoleapplication2\consoleapplication2.cpp 10
Error C2065 'cin': undeclared identifier ConsoleApplication2 c:\users\admin\source\repos\consoleapplication2\consoleapplication2\consoleapplication2.cpp 9
Error C2065 'a': undeclared identifier ConsoleApplication2 c:\users\admin\source\repos\consoleapplication2\consoleapplication2\consoleapplication2.cpp 8
Error C2065 'a': undeclared identifier ConsoleApplication2 c:\users\admin\source\repos\consoleapplication2\consoleapplication2\consoleapplication2.cpp 9
Error C2065 'a': undeclared identifier ConsoleApplication2 c:\users\admin\source\repos\consoleapplication2\consoleapplication2\consoleapplication2.cpp 10
Upvotes: 1
Views: 141
Reputation: 141648
#include "stdafx.h"
should be the first line of the file. Any lines before it are ignored, so you get errors because string
is not recognized.
Upvotes: 1