PDA

View Full Version : [ubuntu] Looking for advice on learning c/c++



celticbhoy
March 8th, 2009, 02:03 AM
After a couple of years using Ubuntu, I would now like to learn how to code in c/c++. To give a bit of background, it has been a number of years since I coded, and then it was visual basic, and pascal.

What I want to know is the best IDE to use, and any online resources to use, tutorial sites would be a bonus. I have googled and been completely snowed under by the amount of options, so I would like advice on the best way to go.


Thanx in advance for any help.

DGortze380
March 8th, 2009, 02:22 AM
After a couple of years using Ubuntu, I would now like to learn how to code in c/c++. To give a bit of background, it has been a number of years since I coded, and then it was visual basic, and pascal.

What I want to know is the best IDE to use, and any online resources to use, tutorial sites would be a bonus. I have googled and been completely snowed under by the amount of options, so I would like advice on the best way to go.


Thanx in advance for any help.

Basic tutorials, you can't beat http://www.cprogramming.com/


When starting out:

I would suggest a basic text editor, I prefer vim, and command line g++.

geany if nice for simple code as well.

For a full IDE, I've heard goo things about eclipse, but I use Xcode and OS X my self so some one else will have to chime in about that.

celticbhoy
March 8th, 2009, 02:35 AM
I have installed eclipse, but it looks over complicated for beginners use to me, might be wrong will take advice on that though. Will have a look at your tutorial advice, I had a look at one and although it was clear and easy, the actual syntax was wrong for the GNU G++ installed in Ibex.

DGortze380
March 8th, 2009, 02:38 AM
I have installed eclipse, but it looks over complicated for beginners use to me, might be wrong will take advice on that though. Will have a look at your tutorial advice, I had a look at one and although it was clear and easy, the actual syntax was wrong for the GNU G++ installed in Ibex.

shouldn't be. check for typos, or post the code here and we can help you debug it.

celticbhoy
March 8th, 2009, 02:45 AM
This is the first little prog :-

\* 0001_hello.cpp *\
#include <iostream>
using namespace std;
int main()
{
cout << end1 << "Hello World";;
return 0;
}

As I say it wont compile, and even the line explaining how to compile gives invalid options. with an unknown option in -q

DGortze380
March 8th, 2009, 02:53 AM
This is the first little prog :-

\* 0001_hello.cpp *\
#include <iostream>
using namespace std;
int main()
{
cout << end1 << "Hello World";;
return 0;
}


Don't need any options for this simple program.

Line 5: endl (lowercase L) not end1
Line 5: one ; not two

fix that and run

g++ hello.cpp -o hello
(replace hello w/ your file name)

./hello

celticbhoy
March 8th, 2009, 03:04 AM
OK first appologies for typo's :redface:

But still getting this on compile :-

hello.cpp:1: error: stray ‘\’ in program
hello.cpp:1:4: error: invalid suffix "_hello.cpp" on integer constant
hello.cpp:1: error: stray ‘#’ in program
hello.cpp:1: error: expected unqualified-id before numeric constant
hello.cpp:1: error: expected constructor, destructor, or type conversion before numeric constant
hello.cpp: In function ‘int main()’:
hello.cpp:6: error: ‘cout’ was not declared in this scope
hello.cpp:6: error: ‘endl’ was not declared in this scope


Any Ideas ?

DGortze380
March 8th, 2009, 03:10 AM
OK first appologies for typo's :redface:

But still getting this on compile :-

hello.cpp:1: error: stray ‘\’ in program
hello.cpp:1:4: error: invalid suffix "_hello.cpp" on integer constant
hello.cpp:1: error: stray ‘#’ in program
hello.cpp:1: error: expected unqualified-id before numeric constant
hello.cpp:1: error: expected constructor, destructor, or type conversion before numeric constant
hello.cpp: In function ‘int main()’:
hello.cpp:6: error: ‘cout’ was not declared in this scope
hello.cpp:6: error: ‘endl’ was not declared in this scope


Any Ideas ?

Sorry, my version of g++ accepted your comments, but they are incorrect.

try using a single line comment on the first line.

// This is a C++ single line Comment

/* This is a correct C++ Style
Block Comment */

celticbhoy
March 8th, 2009, 03:16 AM
OK that done the trick, but I would still rather take my first steps with a tutorial that wont have any version issues. Anyone point me in the right direction.

DGortze380
March 8th, 2009, 03:23 AM
OK that done the trick, but I would still rather take my first steps with a tutorial that wont have any version issues. Anyone point me in the right direction.

again, cprogamming.com

there are no syntax issue with the compiler, ANSI C++ is ANSI C++ regardless of the compiler.

http://www.cprogramming.com/tutorial/lesson1.html

celticbhoy
March 8th, 2009, 03:27 AM
Cheers DGortez will give it a go - thanx for you time.

celticbhoy
March 8th, 2009, 03:42 AM
Just one last question (hopefully), in the tutorial it states that on some c++ version the IDE will compile for you, is there an IDE for Linux GNU C++ that does that??

DGortze380
March 8th, 2009, 03:45 AM
Just one last question (hopefully), in the tutorial it states that on some c++ version the IDE will compile for you, is there an IDE for Linux GNU C++ that does that??

Any mainstream Linux IDE is going to use g++. Most IDE's will give you a 'compile button', but ultimately it's just passing commands to the command line.

For any of those tutorials, compiling is no more difficult than the hello world you just wrote.