help

#include <iostream>
#include <string>
using namespace std;
int main(void){
string nume;
cin>>nume;
nume.replace('a','1');
cout<<nume;
return 0;
}
wg
hy isn't this working i want to replace a with 1 b with 2 etc
The replace does not search anything. You must tell the exact position that you want to modify.
http://www.cplusplus.com/reference/string/string/replace/
Furthermore, it replaces only one position.

If you want to replace each 'a' with '1', then look at each character in turn:
1
2
3
for ( auto & c : nume ) {
  if ( 'a' == c ) c = '1';
}
Topic archived. No new replies allowed.