I know I can input text from the console using while (std::cin >> str).
When I try the following as an equivalent for loop, I get an unhelpful error in Visual C++ 2010. Why is this technically incorrect?
for (true; true; std::cin>>str)
{
// Get input forever
}
I’m guessing your error is something to the effect of using an uninitialized variable,
str. The reason is because the last argument in the for loop doesn’t execute until after the loop completes the first iteration.Also, if you need an infinite loop you could do this or a number of other loop setups: