Function Requirement: input a string "1-2-3" to cut out "1", "2", and "3 ". Use the string split function in Java. The string in C ++ does not directly provide this function. You need to write it yourself.
The solution provided on the Internet is the three methods here. But I accessed it through JNI. I may not use these vectors in it. I encapsulated them for reference only:
String recogscop = "01-02-03"; cout <recogscop <Endl; int size = recogscop. size (); int Pos = 0; string result [20]; for (INT I = 0, j = 0; I <size; I ++, J ++) {pos = recogscop. find ("-", I); If (Pos =-1) {string subend = recogscop. substr (I, size-I); // The last string result [J] = subend; break;} If (Pos> 0) {string sub = recogscop. substr (I, pos-I); Result [J] = sub; I = POS ;}}for (INT I = 0; Result [I]! = ""; I ++) cout <result [I] <Endl;
Note that the POS of the find result above is greater than 0, indicating that the "-" separator can be found. If it fails, that is, the last separator, the POs will be equal to-1.