How would I go about deleting all '\' characters from a string?
I am using the command line to pass parameters with parenthesis, so anyone who uses my program will need to use '\(', '\), '\', etc.

Recommended Answers

All 2 Replies

just use find() then substr() in a loop

size_t pos;
while( (pos = str.find('\\')) != string::npos)
{
    string tmp = str.substr(0,pos) + str.substr(pos+1);
    str = tmp;
}

Alternatively you can use STL functions:

#include <string>
#include <algorithm>
...
std::string::iterator end_pos = std::remove(str.begin(), str.end(), '\\');
str.erase(end_pos, str.end());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.