Bear with me. Skip to "NOW THE ANOMALY" if my story doesn't help.
This doesn't seem to be a code problem so much as a problem with the nuances of how IDEs work.
I'm a beginner with some barely-mentionable (self-taught) java
experience, actually let's put that in quotes: "experience."
I'm diddling around in a book by Stroustrup himself: Programming principles and Practice using C++ because I don't just wanna learn, I wanna learn the right way.
With
java I kept learning that I was being taught poor programming practice by the well-meaning youtubers whose advice I was consulting, so with C++ I thought I'd find myself a pdf and go straight to the man himself for my knowledge this time.
So I'm on chapter 4, and I just finished making my first program which uses a vector. Yay!
It builds, compiles, runs perfectly OK in code::blocks.
Now, Stroussy's book is set up in such a way that, so far, I prefer modifying my "hello_world" project over and over again as he shows me new examples, instead of making a new project each time.
However, I've decided that I want to copy-paste my compiled .exe file found in the bin folder of my hello_world project into a separate folder outside of the IDE project, each time I complete a new example. My idea is that I'll just rename them to whatever the example in the book is, and I'll be able to go back and see the little programs I've made in action without having necessarily to keep all the project folders and source code as well.
NOW THE ANOMALY:
When I run these .exe files I've made outside of the IDE, they just perform their functions and then immediately close after they're finished. No "process returned 0: Press any key to continue" or any such prompt. I've reckoned that the IDE generates this code for me and that once I'm outside of that environment, the extra code to wait for the user input is deleted, so the console closes immediately.
I've searched for the solution to this, and some have (sadly) suggested using some system pause function that everyone else decried as a horrible idea on account of it being OS-specific and nooby.
Others have recommended this:
1 2 3 4
|
std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;
|
Sadly, this doesn't work and I get an
error: expected primary-expression before '>' token|
Also, I'm still not sure
A) if this would even be a proper fix for every situation in which I'm dealing with a simple console program
B) if (OR WHEN) I really have to do the std:: thing
(background info: Stroustrup has me #include some "std_lib_facilities.h" file that I got off his website so that using std:: seems unnecessary half the time, and he tells me it will continue to be until later in the book.)
C) I don't like that I'm copy-pasting that huge parameter on the cin.ignore without understanding it.
Hope I've made my problem clear enough. Any help is enormously appreciated. Sorry for the huge tl;dr textwall.