So I am beginning to learn C++ and I have this issue where whatever I do pops up in command prompt quickly, like a flash of it. I remember I had this issue before and I was able to add or change something in my code so that I had to press ENTER for it to go away. That way I can actually see my results. If someone could tell me what it was I would really appreciate it.

/* This is a sample of C++ Programming
I called this file sample.cpp like the book said
Rather boring but it's a start. */

#include <iostream>
using namespace std;

// a C++ program begins at main()

int main() 
{ 

    int length; // This Declares a Variable

    length = 7; // This assigns the value of 7 to length

    cout << "The Length is ";

    cout << length; // This Displays 7


    return 0;

}

When you run the program select, Debug > Run without debugging. This makes it so the screen will stay open. Or you could use System("Pause"); but that makes your code un-portable. Or you could use cin.getch or something like that.

I believe it's

system("pause");

system("pause"); worked perfect, thanks a lot!

What compiler are you using?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.