#include<iostream>
#include<vector>
using namespace std;
main() {
int x;
char str[80];
cout << "Enter a number and a string:\n";
cin >> x;
cin.getline(str, 80); //take a string
cout << "You have entered:\n";
cout << x << endl;
cout << str << endl;
}
It will show the error: There were build error https://imgur.com/jY8tYoA
I was try it on onlinegdb, it can run normally. I try create a new project in VS and put the code in but it still not worked
CodePudding user response:
That's a small problem. In C / C, we shoule always write int main().
#include<iostream>
#include<vector>
using namespace std;
int main() {
int x;
char str[80];
cout << "Enter a number and a string:\n";
cin >> x;
cin.getline(str, 80); //take a string
cout << "You have entered:\n";
cout << x << endl;
cout << str << endl;
}
This will solve the error.
And if it is in C language, we can use string instead if char[].
CodePudding user response:
Try to add C plugin or code support extensions for VS code. Check on below link. https://code.visualstudio.com/docs/languages/cpp