splitting a string into an array in C++ without using vector

前端 未结 5 1688
轮回少年
轮回少年 2020-11-28 10:53

I am trying to insert a string separated by spaces into an array of strings without using vector in C++. For example:

using namespace std;
int main(         


        
5条回答
  •  借酒劲吻你
    2020-11-28 11:07

    Here's a suggestion: use two indices into the string, say start and end. start points to the first character of the next string to extract, end points to the character after the last one belonging to the next string to extract. start starts at zero, end gets the position of the first char after start. Then you take the string between [start..end) and add that to your array. You keep going until you hit the end of the string.

提交回复
热议问题