News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

2 basic C::B questions from a newbie

Started by temujin, August 15, 2007, 06:12:55 PM

Previous topic - Next topic

temujin

Dear Forum,

I´m a newbie just starting with C::B to learn C++, wondering about 2 things when compiling and running the standard console program ("Hello World").

#include <iostream>

int main()
{
   std::cout << "Hello world!" << std::endl;
   return 0;
}


1. Where is the code that says "press ENTER to continue" in the output, and how can I disable it? (...yes, I tried to search previous posts).

2. Why do I have to include <iostream> and not <iostream.h>? I thought  this was only possible when explicitly using the namespace in which the library residesin.

best regards
t.

thomas

1. is done by Code::Blocks, it has nothing to do with your program. If you run your program elsewhere, it will not appear.
2. This is the C++ standard for.... 5? 6? years now. There is no reason other than "this is how it is".
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

lubos

you can disable it in project->properties->build target->pause when execution ends  :)

temujin

Quote from: thomas on August 15, 2007, 06:16:02 PM
2. This is the C++ standard for.... 5? 6? years now. There is no reason other than "this is how it is".

Thanks...How do I know which libraries need the .h extension and wich that don´t? E.g.  including windows I need <windows.h>

regards
t.

lubos

Quote from: temujin on August 15, 2007, 06:50:44 PM
Quote from: thomas on August 15, 2007, 06:16:02 PM
2. This is the C++ standard for.... 5? 6? years now. There is no reason other than "this is how it is".

Thanks...How do I know which libraries need the .h extension and wich that don´t? E.g.  including windows I need <windows.h>

regards
t.

c++ standard headers are without .h

thomas

Everything that is not C++ standard, i.e. all Windows headers, all C headers, and anything "old school" take .h. You should use the extension for your own headers too.
Thus, you will want: <windows.h>, <stdio.h>, <stddef.h>, <emmintrin.h> etc...

However, the C++ standard library headers have no extension, so if you use these, you want
<iostream>, <vector>, <map>, <algorithm>, etc...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

killerbot

also c headers (when using in c++ code/compiler) are without .h and you need to put a c in front of them !!

Examples :
<stdio.h> --> <cstdio>
<stdlib.h> --> <cstdlib>

and then everything is available in the std namespace !!!

temujin