9 Replies - 2572 Views - Last Post: 09 December 2011 - 10:50 AM Rate Topic: -----

#1 Nitewalkr  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 177
  • Joined: 17-November 10

Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 07:47 AM

Hay guys;

as the title states, I've been having an issue with the display window. As you rebuild and run the program. It will not give any sort of error but it will successfully rebuild and compile. Tho, the display window will flicker instead of what it suppose to do. Which is, it should stay open.
Now the code that I've been using is working out for me so far, but there has to be another way.

The code that I've been using is:
/*This program is to pause display screen after the program life cycle is ended.*/

#include <iostream>
using namespace std;

void pause()
  {
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max());
  }

/*in main*/

int main()
  {
        cout << "Please enter to continue...\n";
	cin.ignore(numeric_limits<streamsize>::max());
return 0;
  }



And no please do not tell me to run the program from command prompt. It was the first thing I did, and it does pretty much the same thing as I run the program from windows.

so....any ideas?

This post has been edited by Nitewalkr: 09 December 2011 - 07:48 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Visual C++ Express 2010 compile and pausing the display issue

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 07:51 AM

You can either run this program in debug mode, or put a cin.get() after your cin.ignore(). You should also add the third parameter to you cin.ignore().
cin.ignore(numeric_limits<streamsize>::max(),'\n'); 
And don't forget to include the limits include file for numeric_limits.

Jim

This post has been edited by jimblumberg: 09 December 2011 - 07:53 AM

Was This Post Helpful? 0
  • +
  • -

#3 yaKashif  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 03-October 11

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 08:04 AM

Do some thing like this

#include <iostream>
#include <conio>
using namespace std;
void main ()
{
//your code
//your code
//your code
//your code

//at end put these lines remember including # include <conio> at top
char a = getch();
}


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 09 December 2011 - 10:25 AM

Was This Post Helpful? -1
  • +
  • -

#4 Nitewalkr  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 177
  • Joined: 17-November 10

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 08:07 AM

Does it really matter?

I mean visual studio C++ 2008 used to keep the display screen open until you press any key or enter. But in 2010 you have to write a code to keep it on screen. =\

Has no one found a solution that does not require coding an extra function to manage the display screen?

This post has been edited by Nitewalkr: 09 December 2011 - 08:10 AM

Was This Post Helpful? 0
  • +
  • -

#5 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 08:16 AM

Two ideas:
(1) In Visual Studio, click on "Project", and then "Properties" (the last item in the drop-down menu.

That opens up the "Property Pages" menu.
Then, click on Configuration Properties/Linker/System, and in the right column click on SubSystem which will open a drop-down box. In that box, click on the first item "CONSOLE (/SUBSYSTEM:CONSOLE)"

Click OK to close the PropertyPages.

When you run your program, use Ctrl-F5 or "Start without Debugging."

That will hold the VS terminal window open after the program finishes.

Oh, and definitely don't start using conio and getch, which were never part of C or C++ standards and will make your programs non-portable to other systems.


(2) The windows command prompt doesn't behave at all like the MS Visual Studio terminal window. Specifically, the command prompt window never closes just because a program finished running -- it remains open waiting for another command. So if you're having this problem with the command prompt, it sounds like you're trying to prevent YOUR program from ending. That's a different matter -- which, as Jim said, cin.get() should solve.
Was This Post Helpful? 0
  • +
  • -

#6 Nitewalkr  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 177
  • Joined: 17-November 10

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 08:21 AM

I tried running it in command prompt by going in to the directory and simply typing the file with cpp extension.

The cmd was opened from windows so I think thats the reason it didnt stay open. I dont know what the reason was, I just want the output screen to keep itself open so I can view the logic errors. :(

I'll try your trick Sir. r.stiltskin, and reply to this thread if it doesnt work either.
Was This Post Helpful? 0
  • +
  • -

#7 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 09:43 AM

View PostNitewalkr, on 09 December 2011 - 10:21 AM, said:

I tried running it in command prompt by going in to the directory and simply typing the file with cpp extension.

That's not the same as running it in a command window. To do that, you first build (but don't run) the program in MSVS by clicking Build/Build solution on the menubar, or just press F7.

Then open a command window by clicking (on the Windows taskbar) Start/run, which opens the Run dialog box, and then type cmd and click OK.

Now you'll see a command (terminal) window with a command prompt (usually C:\Documents and Settings\[your username]> ). In the command window, navigate to the folder where MSVS stored the .exe file for your program (using cd to change directories as necessary), and then type the name of the .exe file, followed by enter.

-----------

Regarding the project configuration in MSVS, here's how you can avoid that when starting a new project:

Open the New Project window, select Win32 Console Application, type a project name & click OK

That opens the Application Wizard window. DON'T click Finish. Instead, click Next.

On the next window, under "Additional options", click Empty project. Now click Finish.

To add a file to the project (this applies to your initial program (.cpp) file as well as any additional header and source files you want to add to the project) click Project/Add New Item and select the type of file you're adding (initially, C++ File), enter a name for the file, and click Add

You now have an empty file in which to write your program. When ready to test your program, build it by pressing F7, then run it by typing Ctrl-F5 (that means press and hold the Control key while you press the F5 key) and the terminal window will stay open when the program finishes.

This post has been edited by r.stiltskin: 09 December 2011 - 09:46 AM

Was This Post Helpful? 1
  • +
  • -

#8 Nitewalkr  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 177
  • Joined: 17-November 10

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 10:14 AM

oh I see...I've been making empty projects only. =\ This might resolve my issue.

Thanks :D
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 10:28 AM

View PostyaKashif, on 09 December 2011 - 10:04 AM, said:

Do some thing like this

#include <iostream>
#include <conio>
using namespace std;
void main ()
{
//your code
//your code
//your code
//your code

//at end put these lines remember including # include <conio> at top
char a = getch();
}


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:


First, void main() is ALWAYS WRONG in C++...ALWAYS! main MUST return an int.
Second, conio is a non-standard header, and getch() is a non-standard function. Do not suggest their use when a suitable standard replacement for this functionality exists.
Was This Post Helpful? 0
  • +
  • -

#10 Nitewalkr  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 177
  • Joined: 17-November 10

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 10:50 AM

Yes, void main is in C# I believe, you are mixing up the languages. I dont know about conio library. =\

I googled it and many applied this suggested conio lib and getch(), but their problem with windows flicker when pressing Ctrl+F5 remained.

I tried making the further document as a console instead of empty project. It worked! Thanks. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1