Since you said you're creating a small program, you might want to consider taking input as command line arguments.
For example, if the user runs my program foo
from the terminal, they could pass me a path by running foo /path/to/file
. If your path contains spaces, the user would have to pass it between quotation marks like this foo "/path with spaces/to/file"
In order to take command line arguments this way you can do something like this:
int main(int argc, char *argv[]) {
// argc is the amount of arguments the user passed, including the filename
// so in our case argv[0] would return foo
// and argv[1] would return /path/to/file
if (argc == 2) {
// do stuff with argv[1]
// no need for std::cin
} else {
std::cout << "Too many or too few arguments!" << std::endl;
}
}
Of course, this way you can only pass arguments once. If you need consistent console input from the user, the other answer is a better one.