1. Do another read: std::cin.get();
std::cin.get() returns the value that has been entered by the user.
You can either choose to store it in a char, integer, string and more.
e.g. string input = std::cin.get();
std::cout << input << std::endl;
// Basic calculator design:
bool IsRunning = true;
cout << "\n\nChoose an option:\n";
cout << "1. Add numbers\n";
cout << "2. Subtract numbers\n";
cout << "3. End program\n- ";
cin >> Choice;
case 1: AddNumbers(); break; // you'd have to write an AddNumbers() function for this to work.
case 2: SubNumbers(); break; // function call again here for this option.
case 3: IsRunning = false; break; // quit out of your while loop.
default: cout << "\nInvalid input. Try again."; break; // any other input produces this.
Third, opening up other programs/applications is a pretty advanced thing for a beginner, it's probably best to create your own programs for now.
"1. How can I disable if player clicks ENTER then the console doesn't close?
2. How can I detect what did player wrote in console ?
3. How can I open a program ?"
1) You can't. By the time the new-line is detected, the input would've been fed into std::istream. You have to process it. If you want to ignore it completely, you'll have to use the OS's API.
2) Use either std::cin.operator >>(), or place the input into a buffer, then parse the buffer's contents.
3) You mean execute? The safest way is to invoke CreateProcess() (Windows). Alternatively, you can use Qt, but linking an entire library to execute a program is a little extreme. Any suggestions to system() should be ignored, if you know what's good for you.
I have 1 question more. How can i find something in string ?
1 2 3 4 5 6 7 8 9 10
std::string theString("hello somethingHere bye");
std::size_t pos = theString.find("somethingHere");
if (pos != std::string::npos)
std::cout << "The string was found at position " << pos << ".\n";
std::cout << "The string was not found.\n";