0

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;

}

Edited by Dani: Formatting fixed

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Narue
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.