cout on one line?
got the following code, but it prints out on multiple lines, I want it all on 1 line if possible.
If I remove endl from second line, it wont compile, any way around this?
1 2 3 4 5 6
|
vector<string>playerCommands = {"North","South","East","West"};
cout << "Please enter either" << endl;
for (int i = 0; i < playerCommands.size(); ++i) {
cout <<" "<< playerCommands[i];
}
|
Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
int main()
{
const std::vector<std::string> commands { "North", "South", "East", "West" } ;
std::string cmd ;
do
{
std::cout << "Please enter one of" ;
for( const std::string& cmd : commands ) std::cout << ' ' << cmd ;
std::cout << " (case sensitive): " ;
}
while( std::cin >> cmd && std::find( commands.begin(), commands.end(), cmd ) == commands.end() ) ;
std::cout << "commmand: " << cmd << '\n' ;
}
|
Topic archived. No new replies allowed.