0
#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
1
  • 2
    why are you using gcc and not g++? Commented Jan 22, 2012 at 7:14

4 Answers 4

8

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.

Sign up to request clarification or add additional context in comments.

Comments

4

You need to

#include <iostream> 

as well.

Also, compile the file with g++ instead of gcc.

Comments

0

if you want to compile with gcc, you should use printf instead of cout, scanf instead of cin and fprintf instead of fout.

1 Comment

gcc can quite happily compile C++ code, it just needs to be correct C++ code and it will need more explicit instructions with linking it
0

cout, cin etc. take part from library. You must include it to get the program work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.