Linux C++ programming in Linux

Dark Star

Level H
Its been years since i touched cpp :P Yep after 11th I couldn't get much time with it instead started learning Python :P Which failed as well :P

Anyway now I am pretty much serious. I had pretty good experience with cpp in past, had created lots of graphical program including some decent projects.

Now the problem is I don't like to use Windows :P Not at all, not even if it cost me my marks :P Anyway I can do it in Linux and I have started doing it using geany IDE. Very intuitive indeed. But since i was stuck with Turbo C in the past I am not very adept with exquisite features of an IDE, though I have noticed it can create executables, make files and what not :P? Pretty much more than enough for me atm.

Although Geany doesn't offer a GUI editor like QT I am fine with it since i am beginning again :P

Anyway for starters how can I get the changes that are done from CPP Windows and Linux ? For instance I have to use std::cout<< instead of cout<< ? and printf and scanf isn't working, nor many header files that I was adept with, say graphic,stdio and math. ?

Apart from that what else needs to be known, is there any site that provide good numericals regarding cpp ? I am very eager to get strated, have already started a lot but still need guidance on it :) Any books as well ?

Regards
 
I have use g++ compiler for c++ programming in Linux.

cout & cin will not work directly, so have to do this:
After include statements write either:
Code:
using namespace std;
after include statements
OR
attach [std::] before cout/cin.
 
welcome to the world of writing portable c++ systems code :D

printf/scanf should work if you do #include <cstdio>

graphics wont work and not sure about math.

have you read C++ FAQ ParaShift? See this for starters: C++ FAQ LITE

edit: Note this FAQ is referred to by beginners, intermediates and experts alike! just the other day in office we were having a big debate about what is safe in constructors and destructors and what is not - and still no idea :)

it is good to start with standard C++ / STL without relying on a framework like windows or qt etc...

if you face specific problems, post here and people will provide inputs!
 
Dark Star said:
Anyway for starters how can I get the changes that are done from CPP Windows and Linux ? For instance I have to use std::cout<< instead of cout<< ? and printf and scanf isn't working, nor many header files that I was adept with, say graphic,stdio and math. ?

It's not linux or windows, it's the way c++ works. You have used very old ide which supports old version of c++. g++ supports the current version of c++ and hence you need to use namespace std to access almost all standard c++ library identifiers(functions,classes ...).For those functions which are part of the standard c library you just need to include header file without extension .h and prefix c to it.for eg instead of stdio.h use cstdio. Use std::printf instead of printf. There's no graphics library which is part of std c++ library(turbo c++ used to provide one non std one, which you might have used, it would not be available on linux). Use QT / WxWidgets / gtk+ instead.

Dark Star said:
Apart from that what else needs to be known, is there any site that provide good numericals regarding cpp ? I am very eager to get strated, have already started a lot but still need guidance on it :) Any books as well ?
If you are starting off, I would suggest your read some books. IMHO that's the best way to start.Get "Accelerated C++" By Koenig and/or C++ primer by Stan Lippman. Don't go with ordinary ones written by Schildt, Liberty or Indian authors. C++ is a difficult language to master, you need a good book for that. Follow it up with Bjarne Stroustrup's The C++ programming language, Effective c++ series by Scott Meyers, Exceptional c++ series by Herb Sutter.
C++ FAQ on internet is a very good source for learning c++.
You could pm me for anything else :)

Dark Star said:
How to clear the screen?

Using standard c++ you can't do that.You have ncurses library though(linux specific), which can do that.
I recommend doing things the standard unix way, please read something like "The Art of Unix Programming" By Eric Raymond available freely online.
 
Yea why do you want/need to clear the screen? I believe ncurses should be a good thing to use on Linux then again you are going for one platform, what if you want to move to another platform which does not have ncurses? :)

My point is, if you're doing things like clearing screen etc. then why not start now itself with a nice cross-platform toolkit like Qt?
 
Haven't really read through the whole thread, but here are a few suggestions of the top of my head
1. Stick to G++. Turbo C/C++ is crap that does NOT stick to standards.

2. Go through a few STL primers.

3. Dump the IDE and start writing your code in EMACS. It will initially be a big jump, but over time as you get used to it, you will start customizing it to suit your style and it can become the most powerful tool you have at your disposal. I can do pretty much anything I would do through VS2008 in emacs.

4. Don't worry about folks advising you to learn Python. C++ is wayyy more powerful(though others might debate that) and makes for a wayy better base language to learn. Competence in C++ can take you places. Any other languages that you learn should ideally be secondary to C++ so that you can leverage the power of C++ and the few areas in which the secondary languages outshine C++

5. Use google. Use cppreference.com.
 
I think for math ton work you need to compile with the -lm switch.

For clear screen ive used:
system("clear");

clrscr(); wont work as its a borland-implementation specific.
 
+1 to emacs...but I liked Kate/Gedit more...Kate has a console window at bottom to no need to open two windows...one for editor and another console for compiling...and for compiling programs with math functions use -lm switch...
 
stalker said:
3. Dump the IDE and start writing your code in EMACS. It will initially be a big jump, but over time as you get used to it, you will start customizing it to suit your style and it can become the most powerful tool you have at your disposal. I can do pretty much anything I would do through VS2008 in emacs.
emacs is my favorite editor too.
One advantage visual c++ compiler has is it's currently better than gcc(g++) when it comes to detecting errors with wrong usage of stl or detecting memory related errors. Hard with gcc. visual c++ debugger is far superior to gdb. A known fact. Currently there are few C++0X features that visual c++ 2010 supports but gcc doesn't(still c++0x isn't finalized). I therefore believe it would be better to use both. You learn more that way.

stalker said:
4. Don't worry about folks advising you to learn Python. C++ is wayyy more powerful(though others might debate that) and makes for a wayy better base language to learn. Competence in C++ can take you places. Any other languages that you learn should ideally be secondary to C++ so that you can leverage the power of C++ and the few areas in which the secondary languages outshine C++

IMHO, this is not a great advice. C++ is my favorite programming language, that doesn't mean I would recommend using it as your "primary language". python is a simple yet very powerful(depends on what you mean by 'powerful'). comp.lang.c++.moderated is one of the best(if not the best) forum for c++ programmers where c++ luminaries like Bjarne Stroustrup(creator c++), Scott Meyers, Walter Bright(creator of D), Andrei Alexandrescu, Franics Glasborrow and many more chip in quiet frequently. Most there suggest it's better to learn python as the first programming language rather than c++. Even if you know c++, one must know something like python/perl/ruby. C++ is too hard for most purposes.
One of the most famous books on programming "The pragmatic programmer" suggests one learn at least 1-2 programming languages every year. I think that's a sound advice.
Have a look at http://norvig.com/21-days.html
stalker said:
5. Use google. Use cppreference.com.
There's lot of junk on internet, so need to be careful with google. Bjarne's homepage is a good source for sound advice. I believe, books are better for understanding a language. Google for getting answers for specific issues.Might be I am too old for "new ways of learning" :ashamed:
I prefer dinkumware for reference on standard C++.

Konquerror said:
+1 to emacs...but I liked Kate/Gedit more...Kate has a console window at bottom to no need to open two windows...one for editor and another console for compiling...and for compiling programs with math functions use -lm switch...
You could compile/build your programs from within emacs. You could execute too, but I would prefer a separate terminal for that. Anyway, I believe unit testing is very important, and that way you might not need to open a separate terminal to check your program. You could consider boost.test for that. There are many other libraries available.
 
haraakiri said:
IMHO, this is not a great advice. C++ is my favorite programming language, that doesn't mean I would recommend using it as your "primary language". python is a simple yet very powerful(depends on what you mean by 'powerful'). comp.lang.c++.moderated is one of the best(if not the best) forum for c++ programmers where c++ luminaries like Bjarne Stroustrup(creator c++), Scott Meyers, Walter Bright(creator of D), Andrei Alexandrescu, Franics Glasborrow and many more chip in quiet frequently. Most there suggest it's better to learn python as the first programming language rather than c++. Even if you know c++, one must know something like python/perl/ruby. C++ is too hard for most purposes.

Thanks for the clarification, I was too lazy to answer a cheeky advice.

On the other hand, call me old fashioned, but I still stick to vim and gcc. Regression will iron out bugs anyways :P.

+LT

+LT
 
wow lots of C++ geeks coming out of the woodwork... good stuff :D

shameless hiring plug:

anyone interested in working for my company in pune :P see gemstone.com and gemstone.com/customers - we work on the product called gemfire. see GemStone Systems - PuneTech
 
Konquerror said:
+1 to emacs...but I liked Kate/Gedit more...Kate has a console window at bottom to no need to open two windows...one for editor and another console for compiling...and for compiling programs with math functions use -lm switch...

Well I will use EMACS or anyother text editor but the issue is my packages system is broken and I cannot install EMACS atm :P Will give it a shot with openSUSE :) BTW I use Gedit in OpenSolaris :P

stellarhopper said:
I think for math ton work you need to compile with the -lm switch.

For clear screen ive used:

system("clear");

clrscr(); wont work as its a borland-implementation specific.

That system("clear"); thingy not working at all :(

Ohh and please shed some light on lm switch :)

@haraakiri will give MS visual studio a try :)

Thanks all for the valuable input :)
 
Dark Star said:
Well I will use EMACS or anyother text editor but the issue is my packages system is broken and I cannot install EMACS atm :P Will give it a shot with openSUSE :) BTW I use Gedit in OpenSolaris :P

That system("clear"); thingy not working at all :(

Ohh and please shed some light on lm switch :)

@haraakiri will give MS visual studio a try :)

Thanks all for the valuable input :)

Well you can use lm switch to compile programs which use math function, something like this

Code:
gcc -lm myfile.c -o myfile
 
Back
Top