Using the Registry

Split from Tutorial thread

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4

53 Replies - 5347 Views - Last Post: 05 July 2012 - 02:18 PM Rate Topic: -----

#46 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 05 July 2012 - 01:33 PM

View PostSkydiver, on 05 July 2012 - 02:27 PM, said:

value is a wchar_t. If you want to output it's contents, you'll need to use wcout, instead of cout.

system("pause");



Seriously? You are so concerned about optimizing your system, and here you are starting a whole CMD.exe child process to just output "Press any to continue..." and wait for a keypress?


Thank you very much, it works properly now.

If I leave out system("pause") the output flashes by and the window closes before I can read it.
Was This Post Helpful? 0
  • +
  • -

#47 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3616
  • View blog
  • Posts: 11,263
  • Joined: 05-May 12

Re: Using the Registry

Posted 05 July 2012 - 01:43 PM

View PostJimbo7136, on 05 July 2012 - 01:33 PM, said:

View PostSkydiver, on 05 July 2012 - 02:27 PM, said:

value is a wchar_t. If you want to output it's contents, you'll need to use wcout, instead of cout.

system("pause");



Seriously? You are so concerned about optimizing your system, and here you are starting a whole CMD.exe child process to just output "Press any to continue..." and wait for a keypress?


Thank you very much, it works properly now.

If I leave out system("pause") the output flashes by and the window closes before I can read it.


Here are some MSVC and Windows specific options:
Option 1: Press Ctrl-F5.

Option 2:
#include <conio.h>
:
cout << "Press any key to continue...";
_getch();



Option 3: Step through your code by pressing F10.

Option 4: Have a CMD window open where you run your console apps.

This post has been edited by Skydiver: 05 July 2012 - 01:45 PM

Was This Post Helpful? 0
  • +
  • -

#48 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 05 July 2012 - 01:48 PM

View PostSkydiver, on 05 July 2012 - 02:43 PM, said:

View PostJimbo7136, on 05 July 2012 - 01:33 PM, said:

View PostSkydiver, on 05 July 2012 - 02:27 PM, said:

value is a wchar_t. If you want to output it's contents, you'll need to use wcout, instead of cout.

system("pause");



Seriously? You are so concerned about optimizing your system, and here you are starting a whole CMD.exe child process to just output "Press any to continue..." and wait for a keypress?


Thank you very much, it works properly now.

If I leave out system("pause") the output flashes by and the window closes before I can read it.


Here are some MSVC and Windows specific options:
Option 1: Press Ctrl-F5.

Option 2:
#include <conio.h>
:
cout << "Press any key to continue...";
_getch();



Option 3: Step through your code by pressing F10.

Option 4: Have a CMD window open where you run your console apps.


Umm, stupid question maybe, but how are these options better than:

system("pause");
?
Was This Post Helpful? 0
  • +
  • -

#49 jimblumberg  Icon User is online

  • member icon


Reputation: 4131
  • View blog
  • Posts: 12,844
  • Joined: 25-December 09

Re: Using the Registry

Posted 05 July 2012 - 01:48 PM

Why mention _getch()? Why not just use getchar() or cin.get(), both standard functions.

Jim
Was This Post Helpful? 0
  • +
  • -

#50 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3616
  • View blog
  • Posts: 11,263
  • Joined: 05-May 12

Re: Using the Registry

Posted 05 July 2012 - 01:57 PM

View Postjimblumberg, on 05 July 2012 - 01:48 PM, said:

Why mention _getch()? Why not just use getchar() or cin.get(), both standard functions.

Jim


Since he is already on Windows and using VS2010, _getch() would fit right in.

Get getchar() and cin.get() don't work the same as _getch(). The user has to press Enter. So the prompt will have to be "Press Enter to continue...", rather than "Press any key to continue...". Additionally, "pause" does not echo any input, while getchar() and cin.get() echo inputs until Enter is pressed. _getch() does not echo and returns immediately when a key is pressed.
Was This Post Helpful? 1
  • +
  • -

#51 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3616
  • View blog
  • Posts: 11,263
  • Joined: 05-May 12

Re: Using the Registry

Posted 05 July 2012 - 02:04 PM

View PostJimbo7136, on 05 July 2012 - 01:48 PM, said:

View PostSkydiver, on 05 July 2012 - 02:43 PM, said:

View PostJimbo7136, on 05 July 2012 - 01:33 PM, said:

View PostSkydiver, on 05 July 2012 - 02:27 PM, said:

value is a wchar_t. If you want to output it's contents, you'll need to use wcout, instead of cout.

system("pause");



Seriously? You are so concerned about optimizing your system, and here you are starting a whole CMD.exe child process to just output "Press any to continue..." and wait for a keypress?


Thank you very much, it works properly now.

If I leave out system("pause") the output flashes by and the window closes before I can read it.


Here are some MSVC and Windows specific options:
Option 1: Press Ctrl-F5.

Option 2:
#include <conio.h>
:
cout << "Press any key to continue...";
_getch();



Option 3: Step through your code by pressing F10.

Option 4: Have a CMD window open where you run your console apps.


Umm, stupid question maybe, but how are these options better than:

system("pause");
?


Why add overhead to your program when you don't need it?

RTFM: system(): http://msdn.microsof...(v=vs.100).aspx

system() goes and fires up another process: the command interpreter.

Ctrl-F5 just has Visual Studio run your program, and it waits for you to press a key.

_getch() runs within your program and waits for a key.

Stepping through your program runs your program and you can examine your variables, or look at the program output at your leisure.

Running your program in a CMD window just lets your program run and you don't have to worry about calling _getch() or system().
Was This Post Helpful? 0
  • +
  • -

#52 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 05 July 2012 - 02:07 PM

View PostSkydiver, on 05 July 2012 - 03:04 PM, said:

View PostJimbo7136, on 05 July 2012 - 01:48 PM, said:

View PostSkydiver, on 05 July 2012 - 02:43 PM, said:

View PostJimbo7136, on 05 July 2012 - 01:33 PM, said:

View PostSkydiver, on 05 July 2012 - 02:27 PM, said:

value is a wchar_t. If you want to output it's contents, you'll need to use wcout, instead of cout.

system("pause");



Seriously? You are so concerned about optimizing your system, and here you are starting a whole CMD.exe child process to just output "Press any to continue..." and wait for a keypress?


Thank you very much, it works properly now.

If I leave out system("pause") the output flashes by and the window closes before I can read it.


Here are some MSVC and Windows specific options:
Option 1: Press Ctrl-F5.

Option 2:
#include <conio.h>
:
cout << "Press any key to continue...";
_getch();



Option 3: Step through your code by pressing F10.

Option 4: Have a CMD window open where you run your console apps.


Umm, stupid question maybe, but how are these options better than:

system("pause");
?


Why add overhead to your program when you don't need it?

RTFM: system(): http://msdn.microsof...(v=vs.100).aspx

system() goes and fires up another process: the command interpreter.

Ctrl-F5 just has Visual Studio run your program, and it waits for you to press a key.

_getch() runs within your program and waits for a key.

Stepping through your program runs your program and you can examine your variables, or look at the program output at your leisure.

Running your program in a CMD window just lets your program run and you don't have to worry about calling _getch() or system().


Points taken.

I'll do it as you suggest. I'm thinking option 2 for convenience sake.
Was This Post Helpful? 0
  • +
  • -

#53 jimblumberg  Icon User is online

  • member icon


Reputation: 4131
  • View blog
  • Posts: 12,844
  • Joined: 25-December 09

Re: Using the Registry

Posted 05 July 2012 - 02:07 PM

Requiring another header file inclusion just to hold the command window open when running this though his IDE is overkill in my opinion. He is already using iostream so just use the iostream solution.

Jim
Was This Post Helpful? 0
  • +
  • -

#54 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3616
  • View blog
  • Posts: 11,263
  • Joined: 05-May 12

Re: Using the Registry

Posted 05 July 2012 - 02:18 PM

View Postjimblumberg, on 05 July 2012 - 02:07 PM, said:

Requiring another header file inclusion just to hold the command window open when running this though his IDE is overkill in my opinion. He is already using iostream so just use the iostream solution.

Jim


True. But we MSVC users are spoiled by precompiled headers, so the extra header only costs on the first compile. :-) And the MSVC runtime DLL is already loaded into memory by the time main() gets called.

Personally, I just always use Ctrl-F5 for my quick and dirty programs written in the MSVC IDE. For more involved programs, I have SlickEdit as my editor, and I have separate build and unit test console windows. Full runs are usually launched from either window only if all the unit tests pass.

This post has been edited by Skydiver: 05 July 2012 - 02:21 PM

Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4