C++ 把文件路径中的单斜杠“\”换成双斜杠“\\”

<pre name="code" class="cpp">#include <iostream> 
#include <algorithm>  //必需加这个头文件
#include <string>
using namespace std; 
 
 
int main()
{
       string::size_type pos=0;
       string test="fsffsfd\\fdsfsfd\\fdsfsd";
       cout<<test<<endl;
 
        while((pos=test.find_first_of('\\',pos))!=string::npos)
        {
            test.insert(pos,"\\");//插入
            pos=pos+2;
        }
    cout<<test<<endl;
 
    return 0;
} 



版权声明:本文为huixingshao原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。