Reputation: 3
My assignment dictates that unless something is entered by the keyboard, nothing will happen. However, I cannot prompt the user to enter anything. My loop looks something like this:
while(true){
"Enter a string to continue: ";
//wait for input
//based on input, do this.
}
The program basically pauses until the user enters a string input without being prompted to, if that makes sense.
The terminal will look blank until the user enters something and then my program kicks in based on the input. Would a simple cin work?
Upvotes: 0
Views: 4082
Reputation: 126
you will need to create a string variable to hold the users input. For example,
string name;
cin >> name;
cout << "you entered: " << name << endl;
now name will store the users input.
Upvotes: 1
Reputation: 75062
You may want this:
#include <iostream>
#include <string>
int main(void) {
for(;;){ // same meaning as while(true){
std::string str;
std::cout << "Enter a string to continue: " << std::flush;
std::cin >> str; // or std::getline(std::cin, str);
// based on the input, do something
}
}
Upvotes: 0