Reputation: 89
I have just setup the VS Code to run C++ using the YouTube video
Now when I write a simple code
#include <iostream>
using namespace std;
int main()
{
cout << "Enter your first name:";
cin << first_name;
cout << "Your name is" + first_name;
return 0;
}
I keep getting the error
PS C:\Users\raman\OneDrive\Documents\C++_Projects> cd "c:\Users\raman\OneDrive\Documents\C++_Projects\" ; if ($?) { g++ Input.cpp -o Input } ; if ($?) { .\Input }Input.cpp: In function 'int main()':
Input.cpp:8:18: error: 'first_name' was not declared in this scope
8 | cin << first_name;
Upvotes: 0
Views: 65
Reputation: 1203
Your code has two problems:
first_name
is not declaredcin
uses >>
, not <<
#include <iostream>
using namespace std;
int main()
{
string first_name;
cout << "Enter your first name:";
cin >> first_name;
cout << "Your name is" + first_name;
return 0;
}
Upvotes: 3