1 <pre name="code" class="cpp"> 2 #include <iostream> 3 #include <algorithm> //必需加这个头文件 4 #include <string> 5 using namespace std; 6 7 8 int main() 9 { 10 string::size_type pos=0; 11 string test="fsffsfd\\fdsfsfd\\fdsfsd"; 12 cout<<test<<endl; 13 14 while((pos=test.find_first_of(‘\\‘,pos))!=string::npos) 15 { 16 test.insert(pos,"\\");//插入 17 pos=pos+2; 18 } 19 cout<<test<<endl; 20 21 return 0; 22 }
转自:http://blog.csdn.net/huixingshao/article/details/46910761
参考:https://msdn.microsoft.com/en-us/library/syxtdd4f.aspx#basic_string::find_first_of