Exclamation[Help] with simple C++ program...

Posts 1–5 of 5 · Page 1 of 1
[Help] with simple C++ program...
Ok so I have a bit of code:
Code:
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string firststring = "Did this work? ";
  string secondstring("If it did then I will be happy :D");
  cout << firststring << endl;
  cout << secondstring;
  return 0; 
}
Which works fine, my problem is every time I run it, it only stays open for a fraction of a second, then closes, what do I need to do to make it stay open until I close it? Thanks!

Oh and using Dev-C++ 4.9.9.2 if it makes any difference...
In your code type:
Code:
cin.get();
Thank you! Worked!

/Mods please close.
hey
i got a problem with a simple c++ program ,
when i run the program , it opens but the text wont show up .



Code:
// sample2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream> 
using namespace std;
int main()

{ 
		cin.get();

	cout << "C++ is power programming."; 

	return 0;
}
thank you lalakijilp . thanked u .
simple c++ program , problem ..jpgattachment deleted · 16 downloads before removal
Quote Originally Posted by Drake View Post
hey
i got a problem with a simple c++ program ,
when i run the program , it opens but the text wont show up .



Code:
// sample2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream> 
using namespace std;
int main()

{ 
		cin.get();

	cout << "C++ is power programming."; 

	return 0;
}
if you run a c++ program it completes all the tasks and then closes.
so in this case it would wait for a key input then show the message and then close. this happens at a large speed so you won't see the message.
the only thing you have to do is switch the cin.get() with the message
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us