Write your question here.
Hello, I am trying to use a 'range for' to print the elements of a vector to the screen.
The first for loop came straight out of C++ Primer and works perfectly.
When I run the program, it works until it gets to the last for loop and completely stops when it try's to execute the last cout.
One question I have is that on the cin where I am using the while loop to input the elements from the keyboard, I will 1) type the last word, 2)hit enter to bring cursor down to the next line, then 3)hit Ctrl-break to stop the input loop. I'm not sure if this is the best way to do that or it could be the problem. Using the debugger, everything looks fine up to the last for loop.
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string str("some string");
// print the characters in str one character at a time
for (auto c : str)
cout << c << endl;
// NOW GET CHARACTERS FROM KEYBOARD
string myStr;
vector<string> myV;
cout << "Please enter strings: " << endl;
while (cin >> myStr)
{
myV.push_back(myStr);
}
auto int2 = myV.size();
for (auto i : myV)
{
cout << "The current value is:" << i << endl;
}
return 0;
} Put the code you need help with here.