Question

very odd because I never had this issue before.

std::string input;
std::getline(std::cin, input);
std::string useInput = useInput.substr(0, 15);

trying to figure out what's wrong with my program & I've figured out that for whatever reason when my string is passing the input into the sub string, it's been erasing the data from the string. When I use

std::cout << input;

It displays what I typed without issue or error, but when I try using

std::cout << useInput;

It displays nothing.

Was it helpful?

Solution

You may mean to have: std::string useInput = input.substr(0,15);

instead of std::string useInput = useInput.substr(0, 15);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top