• Log in or sign up for an account here: https://www.sythe.org/login

My first program....

evil-oreo

Member
Joined
Dec 3, 2005
Sythe Gold
0
Messages
40
//Hello Sythe.org
//My first C++ program

#include <iostream>

using namespace std;

int main ()
{

cout << "Hello Sythe.org!" << endl;
return 0; /* I dont know how to make the window stay open though.
Also, this is all from memory. I think I posted a couple programs before, but copyed someone else.*/

}
 
This shows you how to keep it open by waiting for user input.

Code:
//Hello Sythe.org
//My first C++ program

#include <iostream>

using namespace std;

int main ()
{
cout << "Hello Sythe.org!" << endl;
cout << "Press any key to exit...";
getchar();
return 0; 
/* I dont know how to make the window stay open though.
Also, this is all from memory. I think I posted a couple programs before, but copyed someone else.*/
}
 
hi evil-oreo,

If you used dev c++ compiler, add

system("pause");

example:


#include <iostream.h>

using namespace std;

int main ()
{

cout << "Hello Sythe.org!" << endl;

system("PAUSE");

return 0;

}

you can also clear the screen by adding:

system("cls");

example:

#include <iostream.h>

using namespace std;

int main ()
{

cout << "Hello Sythe.org!" << endl;

system("cls");

cout << "Hello world!" << endl;

system("PAUSE");

return 0;

}
 
Member of the Month Winner
Sythe's 10th Anniversary
hi evil-oreo,

If you used dev c++ compiler, add

system("pause");

example:


#include <iostream.h>

using namespace std;

int main ()
{

cout << "Hello Sythe.org!" << endl;

system("PAUSE");

return 0;

}

you can also clear the screen by adding:

system("cls");

example:

#include <iostream.h>

using namespace std;

int main ()
{

cout << "Hello Sythe.org!" << endl;

system("cls");

cout << "Hello world!" << endl;

system("PAUSE");

return 0;

}
That's terrible, terrible code. What if I use a UNIX or *NIX environment? DOS commands are worthless there.

Use cross-platform libraries, if you are to use any at all. It'll save you a lot of trouble.

Edit: In response to the first post, to keep the window open, use the following:

Add the following header:
Code:
#include <conio.h>

Then before you return 0 from your main method, add this:
Code:
getchar();

simple, cross-platform (I think =/) and works generally effectively.
 
Add the following header:
Code:
#include <conio.h>

Then before you return 0 from your main method, add this:
Code:
getchar();

simple, cross-platform (I think =/) and works generally effectively.

1. The getchar() function is defined in the <iostream> include and is therefore cross-platform.

2. The conio.h header which does not include getchar() is not cross-platform. It does however include the similar getch() function which you might have been thinking of.;)
 
First of all i am sorry for providing uncross-platform libraries since I've never been thought about it in my college. And Swan can you pls tell me what is the function to clear the screen? A cross-platform one of course.

Thanks 4 the helps.
 
Nice program ;)

Here is my recommendation:

Code:
//Hello Sythe.org
//My first C++ program

#include <iostream>

using namespace std;

int main ()
{
char quit;
cout << "Hello Sythe.org!" << endl;
cout << "Press any key to quit: ";
cin >> quit;
return 0;
}

simple. Some of the other post are good as well, but i'm not sure if you understand the libraries yet, and I don't think you should be using libraries in your code if you don't understand them.
 
Member of the Month Winner
Sythe's 10th Anniversary
1. The getchar() function is defined in the <iostream> include and is therefore cross-platform.

2. The conio.h header which does not include getchar() is not cross-platform. It does however include the similar getch() function which you might have been thinking of.;)
Thankyou for clearing that up ;)

Now that I try it, Conio does not work on my Linux setup as I thought it would. And yes, I was thinking of getch() ;)

To clear the console output? I've never really had to, and more or less, don't want to. However, you could always Google it. The DOS command for clearing is "cls", where as Linux is just "clear", makes more sense so far as I'm concerned.
 
The DOS command for clearing is "cls", where as Linux is just "clear", makes more sense so far as I'm concerned.
That is correct but unfortunately on Linux you cannot physically "clear" the terminal window. The clear() function simply pushes all of the current characters up until the window is filled with blank lines. :)
 
Windows is a large cooperate cross platform API because of Wine.
 
Member of the Month Winner
Sythe's 10th Anniversary
That is correct but unfortunately on Linux you cannot physically "clear" the terminal window. The clear() function simply pushes all of the current characters up until the window is filled with blank lines. :)
On my setup it clears the console. Must be the way the developers make it happen.

opensourcecd, Wine is a 3rd party compatibility layer for people wishing to use Windows programs without actually installing Windows. It isn't perfect, and fails with most corporate software.
 
duelarena.gg
Back
Top