Reputation: 796
#include<fstream>
using namespace std;
int
main()
{
char name[30];
int marks;
ofstream fout("student.out");
cout<<"Enter name";
cin>>name;
cout<<"Enter marks secured:";
cin>>marks;
fout<<name<<endl;
fout<<marks<<endl;
return 0;
}
please help me compile the above program using gcc . When i compile this program i get the following errors.
stdfile.cpp: In function 'int main()':
stdfile.cpp:12:1: error: 'cout' was not declared in this scope
stdfile.cpp:13:1: error: 'cin' was not declared in this scope
Upvotes: 0
Views: 259
Reputation: 1210
cout, cin etc. take part from library. You must include it to get the program work
Upvotes: 0
Reputation: 1027
if you want to compile with gcc, you should use printf instead of cout, scanf instead of cin and fprintf instead of fout.
Upvotes: 0
Reputation: 206689
std::cin
and std::cout
are in <iostream>
. Please include that, and compile your C++ code with g++
, not gcc
- otherwise you'll get all sorts of linking issues.
Upvotes: 8
Reputation: 40499
You need to
#include <iostream>
as well.
Also, compile the file with g++
instead of gcc
.
Upvotes: 4