cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
help
help
Apr 11, 2018 at 9:58am UTC
ialexsandu
(8)
#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
Apr 11, 2018 at 11:11am UTC
keskiverto
(10402)
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.