मैं निम्नलिखित समारोह में boost/algorithm/string.hpp
में प्रदान की split()
समारोह का उपयोग करने के कोशिश कर रहा हूँ:सी बूस्ट ++: विभाजित करें फ़ंक्शन is_any_of()
vector<std::string> splitString(string input, string pivot) { //Pivot: e.g., "##"
vector<string> splitInput; //Vector where the string is split and stored
split(splitInput,input,is_any_of(pivot),token_compress_on); //Split the string
return splitInput;
}
निम्नलिखित कॉल:
string hello = "Hieafds##addgaeg##adf#h";
vector<string> split = splitString(hello,"##"); //Split the string based on occurrences of "##"
स्ट्रिंग में विभाजित "Hieafds" "addgaeg" "adf"
& "h"
। हालांकि मैं नहीं चाहता कि स्ट्रिंग को एक #
द्वारा विभाजित किया जाए। I सोचें कि समस्या is_any_of()
के साथ है।
फ़ंक्शन को कैसे संशोधित किया जाना चाहिए ताकि स्ट्रिंग केवल "##"
की घटनाओं से विभाजित हो?
split_regex का उपयोग करने का प्रयास करें: http://www.cplusplus.com/faq/sequences/strings/split/#boost-split-regex – user1284631
धन्यवाद =) मुझे लगता है कि यह काम करता है। – Enigman
भी, आप iter_split (vec, str, first_finder ("##") का उपयोग कर सकते हैं; (यह उत्तर देखें: http://stackoverflow.com/a/5710242/1284631) – user1284631