etiquoe
Member level 1
Hi everyone!
i started to learn C++. i'm totally newbie
i'm using Dev C++ compiler.
i tried to run some simple examples from tutorials, like this:
Or this:
No Error when i compiled it, but nothing happen when i ran it. And then i tried to add getchar()function, like this:
and this:
Then it worked.
I don't really understand about getchar() function.why the two examples above can work after i add the line (getchar())?
anyone? please?
Regards
i started to learn C++. i'm totally newbie
i'm using Dev C++ compiler.
i tried to run some simple examples from tutorials, like this:
Code C++ - [expand] 1 2 3 4 5 6 7 #include <iostream> using namespace std; void main () { cout << “Hello, World!\n”; }
Or this:
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <iostream> using namespace std; int main () { int i = 1; while (i<=257) { cout << i << "\n"; ++i; } }
No Error when i compiled it, but nothing happen when i ran it. And then i tried to add getchar()function, like this:
Code C++ - [expand] 1 2 3 4 5 6 7 8 #include <iostream> using namespace std; void main () { cout << “Hello, World!\n”; getchar(); }
and this:
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include <iostream> using namespace std; int main () { int i = 1; while (i<=257) { cout << i << "\n"; ++i; } getchar(); }
Then it worked.
I don't really understand about getchar() function.why the two examples above can work after i add the line (getchar())?
anyone? please?
Regards