c++ - How to split the strings in vc++? -
I have a string "stack + ovrflow * newyork;" I have to divide this heap, overflow, New York
Any ideas ??
First and foremost, if available, I encourage this type of work: tokenizer Always use (see the great answers given below)
Without access to promotion, you have a few options:
You can use C ++ std :: You can use strings and can be parsed using stringstream and gateline (the safest way)
s Td :: string str = "stack + overflow * newyork;"; Std :: istringstream stream (str); Std :: string tok1; Std :: string tok2; Std :: string tok3; Std :: getline (stream, tok1, '+'); Std :: getline (stream, torque 2, '*'); Std :: getline (stream, point 3, ';'); Std :: cout & lt; & Lt; Tok1 & lt; & Lt; "," & Lt; & Lt; Tock 2 & lt; & Lt; "," & Lt; & Lt; Tock 3 & lt; & Lt; Study :: Endel
Or you can use a family of the Fractok family (if Unidod is the answer to an agnostic version, then xtofl comments for warnings about thread protection See), if you are comfortable with four signals
four letters [30]; Strncpy (str, "stack + overflow * new orch;", 30); // points for delimiters * char * result1 = strtok (str, "+"); Char * result2 = strtok (str, "*"); Char * result3 = strtok (str, ";"); // Change these with comos if (result1! = NULL) {* result1 = ','; } If (result 2! = Null) {* result2 = ','; } // output result printf (str);
Comments
Post a Comment