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;
CodePudding user response:
Your code has two problems:
- First
first_name
is not declared cin
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;
}
CodePudding user response:
You have to declare 'first_name' before using it.
string first_name;