-1

So I want to convert every instance of a \ into \\ for using in a function that creates directories.

string stripPath(string path)
{       
    string newpath;  
    for (int i = 0; i <= path.length() ;i++)
    {
        if(path.at(i) == '\\')
        {
            string someString( path.at(i) );
            newpath.append(path.at(i));
            newpath.append(path.at(i));
        }
    else
    newpath.append(path.at(i));
    }
    return newpath;
} 

newpath.append needs a string so I'm trying to create a string out of path.at(i). I get an error on Visual Studio that says no instance of constructor matches the argument list. I imported string already.

Here is the documentation for string:at. I'm quite confused because I think I'm doing it right?

http://www.cplusplus.com/reference/string/string/at/

4

3 回答 3

1

std::string没有任何使用 achar&作为参数的构造函数。调用应该是:

string someString( 1,  path.at(i) );
于 2013-08-15T20:57:45.963 回答
1

附加单个字符通常使用+=运算符完成:

newpath += path.at(i);
于 2013-08-15T20:58:54.917 回答
0

该错误涉及对append的调用,它应该是:

newpath.append(1, path.at(i));
于 2013-08-15T20:54:58.207 回答