I am trying to get a string a want to change the all the characters to the "X"
, this is where i reached till now.
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main() {
string line;
getline(cin, line);
for (decltype(line.size() index = 0; index != line.size(); ++index)) {
line[index] = "X";
}
cout << line << endl;
return 0;
}
I want to change all the characters to "X"
. Please Help.
Updated Code:
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main() {
string line;
getline(cin, line);
for (decltype(line.size()) index = 0; index != line.size(); ++index) {
if (isspace(line[index])) {
line[index] += 1;
continue;
}
else {
line[index] = 'X';
}
}
cout << line << endl;
return 0;
}
It prints !
in the space between strings, how to solve that.