Hi all,
I am a writing a small plugin to a piece of software that allows people to parse python files and return the output to the program, and to do that, i am allowing users to enter their script. However, they can only enter into a single line text box, so their entered code if formatted as a normal c string, i.e.:

import sys\nprint sys.version\n

When this get's to the program, I have a char string filled with that, however the new lines still exist as the two charachters "\" and "n". Is there a function to convert those to their equvalent charachters, or do i have to write a function to replace for each of those combinations. If so, is there an easy solution to diffrentiating between "\\n" and "\n" in a string.

You will have to write your own function. But its pretty simple

int main(int argc, char* argv[])
    std::string str = "Hello\\nWorld\\\\nAnother\\nWorld";
    size_t pos = 0;
    while( pos < str.size() && (pos = str.find("\\n", pos)) != string::npos)
        if( str[pos-1] != '\\')
            // advance past "\\n"
            pos += 2;
    cout << str << "\n";
	return 0;

I suppose that's what i'll have to do.
Now to go off and remember all the special charachters :P
Thanks for the help

This question has already been answered. Start a new discussion instead.