However this output is not a string
Did you mean to use std::ostringstream
instead of std::cout
to receive the results?
The word.at(i) = xxx;
statements already manipulated the word
string, and you have it.
Here's a sample to show how to get a std:string
result, without manipulating word
directly:
#include <iostream>
#include <string>
#include <sstream>
int main() {
std::string word;
char letter;
int i;
std::cout << "Enter a word: ";
std::cin >> word;
std::ostringstream leetWord;
for ( i = 0; i < word.size(); i++) {
if ( word[i] == 'e') {
leetWord << '3';
}
else if ( word[i] == 'i' ) {
leetWord << '1';
}
else if ( word[i] == 'x' ) {
leetWord << '*';
}
else {
leetWord << word[i];
}
}
// Here you can refer to the ostringstream::str() function to
// get a string
std::string theWantedString = leetWord.str();
std::cout << word << " => " << theWantedString << std::endl;
}
See the working sample.