Continue on enter, but accept string value

The code is a bit long, but I basically just need something that will allow my code to continue on as normal if you hit enter (like cin.get() would do), but also allows me to input a string and have it do something else. What can I do?

First time poster, by the way. I appreciate any help. :)

EDIT: Also, sorry if I got any terminology wrong, I'm still relatively new to C++.
Last edited on
std::cin does what you want.

You can use its >> operator or you can use std::cin.getline. (std::getline for stl strings)

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>

int main()
{
	std::string str;
	std::cin >> str; // For formatted input (will split input by spaces and leave newlines)
	std::getline(std::cin, str); // For unformatted input (will store the entire input into the string)
	return 0;
}
Last edited on
getline() did exactly what I needed, thank you very much! :D
Topic archived. No new replies allowed.