Replacing a char with an integer

Hi! I am learning c++ still but in a personal project I came with an issue of trying to replace a single char in a string with a predefined integer.
Here's the code:

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
int a = 01100001;

string convert;
while (true)
{
getline (cin, convert); // Getting input from user
replace (convert.begin(), convert.end(), 'a', a); //Replacing all a's in the user input with the integer 'a'
cout << convert << endl; // displaying the new sentence
}

return 0;
}


What I'm trying to do is to have the 'replace' function find the character 'a' in the string 'convert' and replace it to the value of the predefined integer 'a' (which is binary for 'a'). Any help? I don't know why this isn't working.
Thanks!

P.S- For all who are wondering it is part of a ASCII to Binary converter

The replace line should probably look like this:
 
    replace (convert.begin(), convert.end(), 'a', (char) a);


Also, this line, int a = 01100001; is assigning a huge octal number to the variable a. The decimal equivalent is 294913.

You might try instead, int a = 97;
Last edited on
Topic archived. No new replies allowed.