LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help with C++ in Linux (https://www.linuxquestions.org/questions/linux-newbie-8/help-with-c-in-linux-310863/)

Bondfire 04-07-2005 04:40 PM

Help with C++ in Linux
 
Hi pple,

I have 3 questions re writing C++ programs in Linux.

1) Is there any help section about the C++ headers and functions available in g++ that i can refer to? I want to find out what header files contain which functions..for example outportb() in dos.h writes data to a port in Windows but the function becomes outb() in Linux and under a different header..how can i search under which header file this function falls in? Is there any help menu for g++? the man command only gives me help on linux commands

2) I tried writing my 1st C++ program in Linux but it didn't compile...until i found that i have to write #include <iostream> without the .h but as it is some1 gave me a C++ program in Lunix to me and in that program all headers have .h so how come i got a warning stating that iostream.h was deprecated?

3) I also found out that cout << doesn't work until i have \n at the end like
cout << " Hi \n"; ...why is it this way?

pls your help guys....i new to Linux..am using RedHAT 8.0

Thanks
Bondfire

TruongAn 04-07-2005 05:21 PM

TO SOLVE ALL THE PROBLEM: I suggest you switch to use some IDE such as kdevelop.

1) To find out a list of function available in a .h file, just open this file to have a look.
For example if you open cmath.h, you can see that abs and sqrt function available in this file.

2) Switch to an IDE to deal with this problem

3) cout << must end with a line craft character, \n or <<endl.

Mara 04-07-2005 05:52 PM

Re: Help with C++ in Linux
 
Quote:

Originally posted by Bondfire
1) Is there any help section about the C++ headers and functions available in g++ that i can refer to? I want to find out what header files contain which functions..for example outportb() in dos.h writes data to a port in Windows but the function becomes outb() in Linux and under a different header..how can i search under which header file this function falls in? Is there any help menu for g++? the man command only gives me help on linux commands
More important functions and system functions have their manual pages with needed includes, syntax and description. Try 'man functionname'.

Quote:

2) I tried writing my 1st C++ program in Linux but it didn't compile...until i found that i have to write #include <iostream> without the .h but as it is some1 gave me a C++ program in Lunix to me and in that program all headers have .h so how come i got a warning stating that iostream.h was deprecated?
With the compiler from RH 8.0 you should get warning. It should also compile. Which version of g++ is it exactly?

Quote:

3) I also found out that cout << doesn't work until i have \n at the end like
cout << " Hi \n"; ...why is it this way?
cout data is buffered and printed when it gets a newline sign or when it's flushed, when the buffer is full and, I think, after a certain time. You can also make it unbuffered, but I'm wondering if that's what you really need. Do you need it unbuffered or it's just a question?

sirclif 04-07-2005 06:01 PM

here is a good recource for the functions included in the standard header files and what they do. gcc compiles standard c++, so as long as you use standard functions it should compile. i have never used and IDE, i prefer to program with textfiles and vi.
i don't know why cout wont work for you unless you use a \n. it does not have to have a \n at the end to work. if you leave off the new line character you just get your new command propt on the same line as the last line of your programs output. although, you do know that cout is in the std namespace and has to refered to as std::cout unless you use the

use namespace std;

at the top of your program right?


All times are GMT -5. The time now is 04:14 AM.