\b not showing up

hello,
I am looking to replace an "\b" by "\e[21m" in my text but i can't seem to figure out how to make it look for the character and not a backspace.
here is my code:

size_t bb = line.find("<\b>");
if(bb!=string::npos)
{line.replace(bb, string("<\b>").length(), "\e[21m");
cout << line << endl;
}
You probably need to escape those escape characters: "<\\b>"
Last edited on
@jlb
You probably need to escape those escape characters: "<\\b>"

not necessary.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s("Hello  \b World");
    
    size_t pos = s.find("\b");
    
    cout << "Pos: " << pos << endl;
}

Output is 7.
> not necessary.
true, you may use a raw string literal R"(<\b>)"

but you completely missed the point in your example, as you are searching for the special character '\b' and not for a backslash '\' followed by a 'b'
@ne555,
but you completely missed the point in your example, as you are searching for the special character '\b' and not for a backslash '\' followed by a 'b'


Yes you are right - somehow I thought he wanted to replace the backspace.
In this case I think jlb's idea
You probably need to escape those escape characters: "<\\b>"
is best.
Your raw string literal will not work on older compilers.
Topic archived. No new replies allowed.