Beginnger: frustration right at the "Hello world" step!

R

revyakin

Hi all,

I am a scientist, and I've done quite a bit of programming in scripting
languages, e.g. Python, which I used to analyze data. I am more or
less familiar with the concepts of objects, includes, stdin, stdout,
etc. Now I need to do more complex things, like driving step motors,
analyzing streaming video input via pattern recognition, etc... where
speed is important.

A colleague recommended C++. I thought, I'll just start with the hello
world program and will eventually figure it out. So I bought the Intel
compiler (first one to come up in Google) and installed it.

Right away, it said that it needs Microsoft Visual Studio installed as
a prerequisute. I have the microsoft package, but it does not run: the
license has expired. Well, all includes should be there... What's the
point of selling a compiler which requires having one from another
company?

Then I found several versions of the same Hello World programs on the
web. Here's one

#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}

Neither Intel's, no MS's could not compile this- iostream.h could not
be in the includes. Fine, I searched my comp for "iostream" and found
that the Microsoft folder has "iostream" w/o the .h extension.
Correcting <iostream.h> to <iostream> gave out an error for "cout".
Finally, I found a code which could be compiled by Intel's (but not
Microsoft's):

#include <iostream>
using std::cout;
int main() {
cout << "Hello World!";
return 0;
}

Don't laugh, it took me an hour to figure it out.

Isn't there any "unified" syntax on C++? I did not find any usable
documentation on it on the web. Or does each company follows its own
syntax? And what's this "here's a compiler for $399, but you've got to
have Microsoft's one first"-deal about? Honestly, I did not expect to
start having all this trouble right at the "Hello World" step. With
Python, I just downloaded the thing and it worked right away (at least
at the hello world step).
 
S

Sharad Kala

[snip]
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}

The above code is not correct.
Neither Intel's, no MS's could not compile this- iostream.h could not
be in the includes. Fine, I searched my comp for "iostream" and found
that the Microsoft folder has "iostream" w/o the .h extension.
Correcting <iostream.h> to <iostream> gave out an error for "cout".
Finally, I found a code which could be compiled by Intel's (but not
Microsoft's):

#include <iostream>
using std::cout;
int main() {
cout << "Hello World!";
return 0;
}

This one is correct.
Don't laugh, it took me an hour to figure it out.

Not at all. People on this newsgroup are there to help you.
Isn't there any "unified" syntax on C++? I did not find any usable

There is something called as a C++ Standard which dictates legality of C++
code. For you it's an overkill at this stage to look into the Standard
though.
documentation on it on the web. Or does each company follows its own
syntax? And what's this "here's a compiler for $399, but you've got to
have Microsoft's one first"-deal about? Honestly, I did not expect to
start having all this trouble right at the "Hello World" step. With
Python, I just downloaded the thing and it worked right away (at least
at the hello world step).

Do these things
- Get VC++ 2003 which is free for download and pretty good. Else you could
get g++ 3.x (Using cygwin on Windows)
- Get a good introductory level C++ book. I can recommend 'Accelarated C++'
and 'C++ Primer'.
- For an online tutorial search "Thinking in C++ Bruce Eckel" on google.
- Check the FAQ for comp.lang.c++ (http://www.parashift.com)
- Try some code and post questions here. Also please read the welcome
message for this group - http://www.slack.net/~shiva/welcome.txt

HTH,
Sharad
 
V

Victor Bazarov

I am a scientist, and I've done quite a bit of programming in scripting
languages, e.g. Python, which I used to analyze data. I am more or
less familiar with the concepts of objects, includes, stdin, stdout,
etc. Now I need to do more complex things, like driving step motors,
analyzing streaming video input via pattern recognition, etc... where
speed is important.

A colleague recommended C++. I thought, I'll just start with the hello
world program and will eventually figure it out. So I bought the Intel
compiler (first one to come up in Google) and installed it.

That's a very good compiler.
Right away, it said that it needs Microsoft Visual Studio installed as
a prerequisute. I have the microsoft package, but it does not run: the
license has expired. Well, all includes should be there... What's the
point of selling a compiler which requires having one from another
company?

Perhaps you need to move to an better OS too. Linux comes with a free
compiler and if you have a version of Intel's C/C++, you'd get a very
good setup.
Then I found several versions of the same Hello World programs on the
web. Here's one

#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}

Ugh! What year was that made in, 1885?
Neither Intel's, no MS's could not compile this- iostream.h could not
be in the includes. Fine, I searched my comp for "iostream" and found
that the Microsoft folder has "iostream" w/o the .h extension.
Correcting <iostream.h> to <iostream> gave out an error for "cout".
Finally, I found a code which could be compiled by Intel's (but not
Microsoft's):

Which of many Microsoft compilers did you use? The program is fine and
should be accepted by at least three recent versions, not to mention
their newest beta.
#include <iostream>
using std::cout;
int main() {
cout << "Hello World!";
return 0;
}

Don't laugh, it took me an hour to figure it out.

You're damn lucky. It took me a month to get through my first book on
C++ and that's without a compiler.
Isn't there any "unified" syntax on C++?

You bet your ass there is. The Standard for the language was adopted
in 1998.
I did not find any usable
documentation on it on the web. Or does each company follows its own
syntax?

The language is complex and some compiler makers just don't seem to get
it right. However, by now most have, at least for that simple program.
And what's this "here's a compiler for $399, but you've got to
have Microsoft's one first"-deal about?

Hey, we don't make up the rules of the market. If you have a complaint
about Intel's practices you should take it up with them.
Honestly, I did not expect to
start having all this trouble right at the "Hello World" step. With
Python, I just downloaded the thing and it worked right away (at least
at the hello world step).

So, why didn't you download, say, Dev-C++? I would have worked right
away, and you didn't need to spend money...

BTW, what book on C++ are you reading?

V
 
R

revyakin

Thanks a lot Sharad, I'll try VC++. Is it going to be enough to
communicate with ports and with a video card (the card came with C
libraries, and a manual with list of classes)? Or will I have to buy
additional library packages here and there?
Speaking onon the incorrect code... that one was from about.com.
 
R

revyakin

You're damn lucky. It took me a month to get through my first book on
C++ and that's without a compiler.

I don't know how you did it - I always need an immediate feedback, I
can't just sit there and "study C++" theoretically. I would get bored
in 10 min. With Python, I had a book, but put it away very quickly,
since everything was online... apparently it's not the case with C++.

The Intel compiler is the most recent one
And MS compiler was Microsoft Visual Studio 2003.
 
A

Alf P. Steinbach

* (e-mail address removed):
I am a scientist, and I've done quite a bit of programming in scripting
languages, e.g. Python, which I used to analyze data. I am more or
less familiar with the concepts of objects, includes, stdin, stdout,
etc. Now I need to do more complex things, like driving step motors,
analyzing streaming video input via pattern recognition, etc... where
speed is important.

A colleague recommended C++. I thought, I'll just start with the hello
world program and will eventually figure it out. So I bought the Intel
compiler (first one to come up in Google) and installed it.

There are many fine _free_ C++ compilers.

For Windows I recommend Microsoft's Visual C++ Toolkit (which is a
non-optimizing version of their compiler) and the GNU g++ compiler,
as Sharad Kala also recommended. It is a good idea to use two
different compilers if you want to produce portable code.

Use your Intel compiler to produce the final, optimized program.


Right away, it said that it needs Microsoft Visual Studio installed as
a prerequisute. I have the microsoft package, but it does not run: the
license has expired. Well, all includes should be there... What's the
point of selling a compiler which requires having one from another
company?

Visual Studio is an IDE (editor, integration with compiler, debugger,
version system etc.); presumably Intel's compiler, which I have not
used, integrates with Visual Studio as a "better" more optimizing
replacement for Microsoft's Visual C++ compiler.

Then I found several versions of the same Hello World programs on the
web. Here's one

#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}

This is incorrect, pre-standard (pre-1998) code.

Neither Intel's, no MS's could not compile this- iostream.h could not
be in the includes. Fine, I searched my comp for "iostream" and found
that the Microsoft folder has "iostream" w/o the .h extension.
Correcting <iostream.h> to <iostream> gave out an error for "cout".
Finally, I found a code which could be compiled by Intel's (but not
Microsoft's):

#include <iostream>
using std::cout;
int main() {
cout << "Hello World!";
return 0;
}

Huh, it compiles fine with Visual C++ 7.1.

However, also this code is slightly wanting: to guarantee that it
produces any output the text should include a newline at the end,
or use std::endl or std::flush (I think that's it's name).

Try the following, which is 99% standardconforming C++:


#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
}

Also see the FAQ.

And get yourself a good book (Sharad's suggestion of Accelerated
C++ is very good).


Don't laugh, it took me an hour to figure it out.

Isn't there any "unified" syntax on C++?

There is the C++ ISO standard.
With
Python, I just downloaded the thing and it worked right away (at least
at the hello world step).

That's also the case for C++.

Hm, I wonder whether I would make many folks very happy if I wrote a
modern post-standard current tools C++ tutorial for novices.
 
S

Sharad Kala

Thanks a lot Sharad, I'll try VC++. Is it going to be enough to

You are quite welcome.
communicate with ports and with a video card (the card came with C
libraries, and a manual with list of classes)? Or will I have to buy
additional library packages here and there?
Speaking onon the incorrect code... that one was from about.com.

Please note that Standard C++ does NOT talk about video cards/ports etc. So
you will need to resort to libraries provided by your compiler/OS (check
their documentation). You can get a lot of good platform specific assistance
for VC on on msnews.microsoft.com. Please
read the welcome message I pointed to in my last reply. People on this
newsgroup are in general not be very kind if you post off-topic(i.e.
platform/OS specific) questions.

Sharad
 
F

Frank Looper

Sharad Kala said:
Do these things
- Get VC++ 2003 which is free for download and pretty good. Else you could
get g++ 3.x (Using cygwin on Windows)
- Get a good introductory level C++ book. I can recommend 'Accelarated C++'
and 'C++ Primer'.
- For an online tutorial search "Thinking in C++ Bruce Eckel" on google.
- Check the FAQ for comp.lang.c++ (http://www.parashift.com)
- Try some code and post questions here. Also please read the welcome
message for this group - http://www.slack.net/~shiva/welcome.txt

HTH,
Sharad
Thanks a lot. The advice wasn't directed at me, but it sent me down some
neat paths this evening.

:)
Frank
 
R

Rob Williscroft

Alf P. Steinbach wrote in in
comp.lang.c++:
For Windows I recommend Microsoft's Visual C++ Toolkit (which is a
non-optimizing version of their compiler)

AIUI the free download includes the optimizing compiler, its the the
academic version that comes with a substandard compiler (but includes
the IDE).

Rob.
 
V

Victor Bazarov

I don't know how you did it - I always need an immediate feedback, I
can't just sit there and "study C++" theoretically. I would get bored
in 10 min. With Python, I had a book, but put it away very quickly,
since everything was online... apparently it's not the case with C++.

Well, I found imagining (and understanding) what your code does while
writing it or debugging it a very useful ability, especially in certain
circumstances where some tools are lacking. Besides, when I learned to
program, we did most of our programming on paper with a pencil first.
Reading a book and the source code in it without actually spending time
typing it into an editor then compiling, then running, was rewarding in
more ways than one. You should try it some time, it's like solving
a puzzle (if you like that sort of thing, that is).
The Intel compiler is the most recent one
And MS compiler was Microsoft Visual Studio 2003.

That's a couple of decent compilers. If you don't mind, check the code
again with MS, and do report what errors it complains about and where.
Make sure you're sticking that source into a "console application" and
not a "windows application".

V
 
G

Gernot Frisch

Hi all,

I am a scientist, and I've done quite a bit of programming in
scripting
languages, e.g. Python, which I used to analyze data. I am more or
less familiar with the concepts of objects, includes, stdin, stdout,
etc. Now I need to do more complex things, like driving step motors,
analyzing streaming video input via pattern recognition, etc...
where
speed is important.

A colleague recommended C++. I thought, I'll just start with the
hello
world program and will eventually figure it out. So I bought the
Intel
compiler (first one to come up in Google) and installed it.

Right away, it said that it needs Microsoft Visual Studio installed
as
a prerequisute. I have the microsoft package, but it does not run:
the
license has expired. Well, all includes should be there... What's
the
point of selling a compiler which requires having one from another
company?

Then I found several versions of the same Hello World programs on
the
web. Here's one

#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}

Neither Intel's, no MS's could not compile this- iostream.h could
not
be in the includes. Fine, I searched my comp for "iostream" and
found
that the Microsoft folder has "iostream" w/o the .h extension.
Correcting <iostream.h> to <iostream> gave out an error for "cout".
Finally, I found a code which could be compiled by Intel's (but not
Microsoft's):

#include <iostream>
using std::cout;
int main() {
cout << "Hello World!";
return 0;
}

Don't laugh, it took me an hour to figure it out.

Isn't there any "unified" syntax on C++? I did not find any usable
documentation on it on the web. Or does each company follows its own
syntax? And what's this "here's a compiler for $399, but you've got
to
have Microsoft's one first"-deal about? Honestly, I did not expect
to
start having all this trouble right at the "Hello World" step. With
Python, I just downloaded the thing and it worked right away (at
least
at the hello world step).

For a beginner, get an IDE, that is editor+makefile
generator+compiler+linker in one.
Visual Studio seems to be the best on Win, however Blooshed's (free)
DevC++, and Utlimate++ seem very good for beginners as well.

Your example would compile, however setting up the compiler+enviroment
variables, so everything compiles might be a bit of a problem.
C++ in comparison to Python is like a helicopter vs a rubber boat.
You're way better of if you know it, but learning curve is steep.
 
R

revyakin

Thanks a lot, guys, what a great newsgroup. I am on Chapter 4 of
Thinking in C++. Donloaded VC++ 2003 and testing code examples (no, I
am not a pencil and paper person). Feeling relieved :)
 
P

Pete

Alf P. Steinbach said:
For Windows I recommend Microsoft's Visual C++ Toolkit (which is a
non-optimizing version of their compiler)

Incorrect. The 'Toolkit is their full Pro edition compiler, which includes
optimizing. I can verify that in one of my very computationally-intensive
applications (a software renderer), compiling with /O2 almost doubled the
execution time in comparision with their non-optimizing compiler that came
with VC++2003 Standard.

- Pete
 
A

Alf P. Steinbach

* Pete:
Incorrect. The 'Toolkit is their full Pro edition compiler, which includes
optimizing. I can verify that in one of my very computationally-intensive
applications (a software renderer), compiling with /O2 almost doubled the
execution time in comparision with their non-optimizing compiler that came
with VC++2003 Standard.

Well I stand corrected.

It says what you say at Microsoft's web-page for the toolkit.

I got that incorrect impression from a compiler bug which only
manifested with optimization, and which a well-known C++ expert said
couldn't be reproduced. It turned out, as I recall, that he was using
the toolkit version of the compiler. But now it seems more likely that
in actuality it was the "Standard" version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top