Hello, I'm currently taking a C++ course and the last few weeks have been a complete headache. I have this lab where i'm suppose to remove spaces and I keep getting errors with my code. I have no idea what I'm doing wrong. Can anyone spot my error?
#include <iostream>
using namespace std;
int main() {
string userInput;
getline(cin, userInput);
for (int i = 0; i < userInput.length(); ++i){
if (isspace(userInput.at(i))){
userInput.at(i) = "";
}
}
cout<< userInput <<endl;
return 0;
}
I also tried another code but received the same error
#include <iostream>
using namespace std;
int main() {
string userInput;
getline(cin, userInput);
for (int i = 0; i < userInput.length(); ++i){
if (userInput.at(i) = " "){
userInput.at(i) = "";
}
}
cout<< userInput <<endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
string userInput;
getline(cin, userInput);
for (int i = 0; i < userInput.length(); ++i){
if (isspace(userInput.at(i))){
userInput.at(i) = "";
}
}
cout<< userInput <<endl;
return 0;
}
I also tried another code but received the same error
#include <iostream>
using namespace std;
int main() {
string userInput;
getline(cin, userInput);
for (int i = 0; i < userInput.length(); ++i){
if (userInput.at(i) = " "){
userInput.at(i) = "";
}
}
cout<< userInput <<endl;
return 0;
}