set: how to list not strings starting with given string and ending with `/`?

后端 未结 3 936
忘掉有多难
忘掉有多难 2020-12-22 08:42

for example we have in our set:

 bin/obj/Debug/CloudServerPrototype/ra.write.1.tlog 
 bin/obj/Debug/CloudServerPrototype/rc.write.1.tlog 
 bin/obj/Debug/vc10         


        
3条回答
  •  臣服心动
    2020-12-22 09:15

    Quick example of what you want to do.

    String.find(): http://www.cplusplus.com/reference/string/string/find/

    String.subStr(): http://www.cplusplus.com/reference/string/string/substr/

    string str = "bin/obj/Debug/vc100.pdb";
        string checkString ("bin/obj/Debug");
    
         // Check if string starts with the check string
         if (str.find(checkString) == 0){
          // Check if last letter if a "/"
          if(str.substr(str.length()-1,1) == "/"){
            // Output strating at the end of the check string and for
            // the differnce in the strings.
            cout << str.substr(checkString.length(), (str.length() - checkString.length()) ) << endl;
          }
         }
    

提交回复
热议问题