Programming with G++

It's very basic and I am sure many guys will be able to help me out.

I have been programming quite a bit in Windows with MSVC++ and Dev-C++.. I built simple programs for Windows Console and also did just a very little bit of Win32 Programming... Now I have changed my OS and I am working on Linux.
I am absolutely new to programming in Linux with C++. I am using the built in compiler GNU-G++ most of you must have an idea of! I am starting off with simple console programme. Here is that program.

#include <iostream>
using namespace std;

int main()
{
// I want to get a function here which clears screen before displaying this output...
cout<<"***********************************************************"<<endl;
cout<<"**********************Authored By:*************************"<<endl;
cout<<" Mario Santana "<<endl;
cout<<" madmax.santana@gmail.com "<<endl;
cout<<"***********************************************************"<<endl;
cout<<"***********************************************************"<<endl;
cout<<endl;
cout<<endl;
cout<<"This is a simpe demonstration of the GNU-g++ Compiled C++ Program."<<endl;
cout<<"The program was built by console module of GNU-g++ at Ubuntu Platform."<<endl;
cout<<"Please press any key to exit."<<endl;
cout<<"..."<<endl;
// I want to get a function here which prompts the screen for input (Keyboard hit)
// Also the function should not echo the input on screen.
// In the end I want to put a function which exits the program, erases all the output off the screen and take the user back to exactly where he was...
// That would possibly define the basics of a nice console program for linux. :D
return 0;
}


Now I have following questions...

- In G++ whenever I include non-standard libraries like stdio.h or stdlib.h or even conio.h, it gives error that the library doesn't exist. Any ideas about downloading these libraries and inserting hem into the default include folder of G++???

- In the program above, please have a look at the comments at the beginning and end of program. Even if I use only standard libraries, how do I achieve my objectives that I have mentioned in the comments.

- Finally, all the folks there, I would like to ask your help regarding the complier... Is there an IDE for C++ in linux which supports the simple console programming like above??? Because G++ is very tiresome, I edit my file, then compile and then if there is an error I again open the editor, again compile it and if there is an error again, huffff! Is there an IDE like MSVC++ in linux? I have tried KDevelop and Anjuta but they are for extensive KDE and Qt programming and I have no idea how to compile a simple console program in any of them... Please, any idea!???
stdio.h is for C, for C++ include cstdio (the same for cstdlib ) Anyway, I can compile fine a program including stdio.h with g++, which version do you have? Which options are you compiling with?
Regarding conio.h, NEVER use it!

to clear the screen see: http://www.cplusplus.com/forum/articles/10515/

Is there an IDE like MSVC++ in linux?
I suggest you Code::Blocks
Thanks a lot Bazzy!
I once read that about cstdlib and cstdio... I simply had forgotten... it's been almost 6 months since i last did any programming in C++.
And I don't know the version of my G++... How to find that out???
And OK. i won't use it. But may I know the reason? Some security malfunction?

Thanks for that link about clearing the screen.
And how to download Code::Blocks?\
Thanks again fella!
In G++ if I am using
#inlcude <curses.h>

I have to link the library with -lcurses argument... I need a compiler which automatically links the libraries!
But may I know the reason?
It is old and it does nothing useful. If you want some TUI library go for ncurses

And how to download Code::Blocks?
Which Linux distro do you have? You should find C::B in the package repositories

And I don't know the version of my G++... How to find that out???
From the terminal: g++ -v
K...
G++ Version
t=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)


As clear from above output, I am using Ubuntu.
Furthermore it is Ubuntu Jaunty Jackalope (9.04)
And when I write C::B in my console, it returns "Command not found". That is how I search for the programs. I simply write the command. If it is available and installed, it runs the program. If it is available and not installed it returns "Program so and so is not currently installed. You can install it using apt-get bla bla..." If neither, it returns simple "Command not found..."

So does that mean Code::Blocks isn't installed on my system and it is not available for my distro either???
And also how do I know which libraries of C++ are already installed in my system and which are standard ones. And where do i get new libraries...

I am sorry if I am bothering you! But I have no other way of knowing all that! Consider it my limitation please and don't mind too much questioning by me.
Last edited on
It says to use apt-get only on common programs when it doesn't find one but codeblocks is in jaunty repositories:
sudo apt-get install codeblocks

where do i get new libraries...
I install everything via APT. If you are looking for 'somelibrary' ( presume that is the actual name of the library ) You need to first look for the package name for that library: apt-cache search somelibrary it will show a lot of package, read those starting with 'lib'. If you find the wanted package you can install it: sudo apt-get install somelibrarypackagename. If you already have that library installed it will say "somelibrarypackagename is already the newest version"

If you don't like the command line too much you can use synaptic. It is the same as APT but with a GUI showing you which packages you already have etc.

You can find all the library header files in /usr/include

Standard libraries are these: http://www.cplusplus.com/reference/
( iostream, STL, string, C library, some few other )



[EDIT] g++ 4.3 is the second newest version (the same I use). If you want g++ 4.4 install gcc-snapshot
Last edited on
Thanks a lot Bazzy!
Will Codeblocks automatically link the libraries and is it a GUI package???
Will Codeblocks automatically link the libraries
It has some project templates linking to the most common libraries.
If you are using some other library is not mush difficult to link to it, you just need to add the .so / .a files to the linker settings ( found in Build Options dialog )

is it a GUI package???
What? It is an IDE
Grrrrrrrrrreaaaaaaaaaaaaaaaat Man!!!
You are awesome... That was exactly what I needed!
Thanks a lot again and again!
Just one niche pal!
I don't know how to get libcurses.

madmax@Mean-Machine:~$ sudo bash
[sudo] password for madmax:
root@Mean-Machine:~# apt-get install libcurses
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find package libcurses


I don't know whether it is installed in my system even. How can I link to it when I don't even know what is its name!
Last edited on
Try installing the packages libncurses5 and libncurses5-dev ( library files in /usr/lib : libncurses.a and libncurses.so )
Last edited on
closed account (S6k9GNh0)
Linux distros normally give you a package managers to help download and install this. THe package probably looks like what Bazzy pointed out. If not, you can go to the site and manually add them in an orderly fashion to your header and library stockpiles in /usr/lib and /usr/include.
Look, as a new Linux programmer you could try this thread http://ubuntuforums.org/showthread.php?t=554070
Its a pretty good site for Linux newbie programmer. Also for using any library you have to install the main library package and the dev package(like libncurses5 is the library and libncurses5-dev is the dev package with headers). For linking libraries you have to set compiler option in your IDE(Like I use geany and thats "set includes and arguments" box I have added linking to all my daily using libraries). And as for conio.h thats a windows/dos only header. You cant use any of that but there is alternatives in Linux for all of that.
Welcome for joining Linux World. :-)
Topic archived. No new replies allowed.