Possible Duplicate:
How do I tokenize a string in C++?
hello every one i want to divide my string into two parts based on '\t' is there any built in function i tried strtok but it take char * as first in put but my variable is of type string thanks
Possible Duplicate:
How do I tokenize a string in C++?
hello every one i want to divide my string into two parts based on '\t' is there any built in function i tried strtok but it take char * as first in put but my variable is of type string thanks
#include <sstream>
#include <vector>
#include <string>
int main() {
   std::string str("abc\tdef");
   char split_char = '\t';
   std::istringstream split(str);
   std::vector<std::string> token;
   for(std::string each; std::getline(split, each, split_char); token.push_back(each));
}
 
    
    Why can't you use C standard library?
Variant 1. Use std::string::c_str() function to convert a std::string to a C-string (char *)
Variant 2. Use std::string::find(char, size_t) to find a necessary symbol ('\t' in your case) than make a new string with std::string::substr. Loop saving a 'current position' till the end of line.
