I was wondering if there was any possible method of copying/assigning a whole getline(cin, str) input to a separate string? This is what I have so far:
string str;
// possibly another string strOriginal?
getline(cin, str);
for (i = 0; i < str.size(); ++i) {
if (isspace(str.at(i))) {
str.replace(i, 1, "");
}
}
cout << str;
// cout << strOriginal;
I need to get rid of all spaces inside a string and then work with that new string while also being able to access the original string input later on.
Ex. If I were to input a string such as "Hello everyone" the code would output "Helloeveryone" which is what I need, however, I also need to be able to access the original string.
If anyone could help and inform me if this is possible and how to do so, that would be greatly appreciated, thanks!