PDA

View Full Version : Compiling Error C



stamatiou
June 13th, 2011, 08:57 PM
Hey guys,
I use ubuntu 11.04 and I installed the build-esential package and created the .c file. When I entered the command cc -c first.c it shows me

first.c:1:20: warning: extra tokens at end of #include directive
first.c:1:40: fatal error: iostream: No such file or directory
compilation terminated.
What should I do? ](*,)

simeon87
June 13th, 2011, 08:58 PM
Can you post the source? You most likely made a mistake on an #include line. There should not be a semi-colon at the end, if that happens to be the problem.

dwhitney67
June 13th, 2011, 09:01 PM
Here we go again...

If you are programming in C, please include stdio.h.

If you are programming in C++, which by the way, is a different language, then by all means include iostream. However with C++, you need to name your source file with one of the following extensions: .C, .cxx, or .cpp (the most common). If I missed one, then forgive me. Also, you compile C++ code using 'g++', not 'gcc' or 'cc'.

stamatiou
June 13th, 2011, 09:11 PM
Can you post the source? You most likely made a mistake on an #include line. There should not be a semi-colon at the end, if that happens to be the problem.

#include <iostream>using namespace std;

int main()
{
cout << "Hello World \n";
return 0;
}[/CODE
Also I changed it into [CODE]#include <stdio.h>

int main()
{
cout << "Hello World \n";
return 0;
}
and it shows me now:

first.c: In function ‘main’:
first.c:5:1: error: ‘cout’ undeclared (first use in this function)
first.c:5:1: note: each undeclared identifier is reported only once for each function it appears in

tbastian
June 13th, 2011, 09:17 PM
#include <iostream>using namespace std;

int main()
{
cout << "Hello World \n";
return 0;
}[/CODE
Also I changed it into [CODE]#include <stdio.h>

int main()
{
cout << "Hello World \n";
return 0;
}
and it shows me now:

first.c: In function ‘main’:
first.c:5:1: error: ‘cout’ undeclared (first use in this function)
first.c:5:1: note: each undeclared identifier is reported only once for each function it appears in

You're writing a c++ program here. Change 'stdio.h' back to 'iostream' and compile with g++.

stamatiou
June 13th, 2011, 09:19 PM
You're writing a c++ program here. Change 'stdio.h' back to 'iostream' and compile with g++.
Can you write me a code for a hello world c program and the command to compile it and execute it?

dwhitney67
June 14th, 2011, 12:07 AM
#include <iostream>

int main()
{
std::cout << "Hello World." << std::endl;
}


or



#include <iostream>

int main()
{
using namespace std;

cout << "Hello World." << endl;
}


Say you save either of the programs above into a file called "hello.cpp", then you would compile it using:


g++ -Wall -pedantic hello.cpp -o hello

Man-pages are available for most commands; feel free to peruse them, and if afterwards you have questions, then post back here.

stamatiou
June 14th, 2011, 01:38 PM
#include <iostream>

int main()
{
std::cout << "Hello World." << std::endl;
}
or



#include <iostream>

int main()
{
using namespace std;

cout << "Hello World." << endl;
}
Say you save either of the programs above into a file called "hello.cpp", then you would compile it using:


g++ -Wall -pedantic hello.cpp -o hello
Man-pages are available for most commands; feel free to peruse them, and if afterwards you have questions, then post back here.
No, I mean in C, not C++.

tbastian
June 14th, 2011, 01:40 PM
No, I mean in C, not C++.


#include <stdio.h>

int main ( int argc, char ** argv )
{
printf ( "Hello, World!\n" );
return 0;
}



gcc -o hello helloWorld.c
./hello

assuming you named your file helloWorld.c

velle frak
June 14th, 2011, 01:41 PM
#include<stdio.h>

int main() {
printf('Hello world.\n");
return 0;
}