ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello bodies!
I'm using Redhat9
And now I'm learning to program under this OS.
This is my gcc information:
[root@localhost bin]# gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
I write a simple "Hello World!" program:
#include
int main()
{
printf("Hello World!");
exit(0);
}
I had tried two times,but it gets wrong as follow:
1.
[root@localhost GratuationDesign]# gcc hello.c
hello.c:1:10: #include expects "FILENAME" or <FILENAME>
2.
[root@localhost GratuationDesign]# gcc hello hello.c
gcc: hello: 没有那个文件或目录(means:can't find that file)
hello.c:1:10: #include expects "FILENAME" or <FILENAME>
Then I modified my program as follow:
#include <iostream>
int main()
{
printf("Hello World!");
exit(0);
}
The result is:
1.
[root@localhost GratuationDesign]# gcc hello.c
hello.c:1:20: iostream: 没有那个文件或目录(means:can't find that file)
Try #include <iostream.h> and since int main() has integer return type, include an integer return value: such as return 1; after exit, which isn't really needed.
yea, your mixing C and C++. it looks like your trying to write a C program since your using the C compiler (gcc), the printf() function is in the <stdio.h> header, so use the include graemef suggested. If you're trying to compile C++ code, you use the command g++ file.cpp. In which case you would use the include <cstdio> to use the printf() function.
C header files are .h, but C++ header files do not have the .h extention. the compiler will complain sometimes if you try include something like <stdio.h> and use the C++ compiler (g++). however, all C header files are available in C++, you just remove the .h from the header file and add a c to the beginning. so...
<stdio.h> becomes <cstdio>
<stdlib.h> becomes <cstdlib>
and so on...
Thak you very much
I'v got it! Though I'm still not very clear,but I'will try later on.
I reply this letter late beacuse the problem 0f Time Zone. Sorry! Haha
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.