// Osman Zakir
// 12 / 18 / 2016
// Bjarne Stroustrup: Programming: Principles and Practice Using C++ 2nd Edition
// Chapter 4 Section 4.6.3 A Numeric Example (for vectors)
// An example code listing to illustrate a vector of doubles as temperatures
#include "../../std_lib_facilities.h"
int main()
{
vector<double> temps;
for (double temp; cin >> temp;)
{
cin.ignore();
temps.push_back(temp);
cin.ignore();
}
for (constdouble &x : temps)
{
cout << x << "\n";
}
cin.ignore();
keep_window_open();
}
But the calls to cin.ignore() and keep_window_open() (the latter from std_lib_facilities.h from Stroustrup's book's library access header) fail and the program exits without waiting for a key press. Please help.
Edit for update: doing it like this seems to have helped:
// Osman Zakir
// 12 / 18 / 2016
// Bjarne Stroustrup: Programming: Principles and Practice Using C++ 2nd Edition
// Chapter 4 Section 4.6.3 A Numeric Example (for vectors)
// An example code listing to illustrate a vector of doubles as temperatures
#include "../../std_lib_facilities.h"
int main()
{
vector<double> temps;
for (double temp; cin >> temp;)
{
cin.ignore();
temps.push_back(temp);
}
for (constdouble &x : temps)
{
cout << x << "\n";
}
cin.clear();
cin.ignore();
keep_window_open();
}
But other ideas, if any, for doing it better are appreciated anyway. And if anyone wants to see the code in that header, just let me know and I'll post it.
1. Execute your console programs from a console.
a. ¿Do you know what `cin.ignore()' does? You seem to be putting it everywhere.
you read the input as while( cin>>input ), for the loop to end, then stream must become invalid.
`keep_window_open()' needs a valid stream, hence you need to do cin.clear()
Either from a console or from an IDE is fine. Running it directly from the .exe file requires that function, but it's not like I can test for that from within my code.
I think I can mark this as solved now. The code is now running as intended for keep_window_open();