Parsing file names from a character array

2019-09-05 23:35发布

问题:

I apologize if this has been asked before but I am trying to parse an array of characters in away I can obtain filenames.

Here is an example of the character array I end up copying in.

picture1.bmp   file2.txt   random.wtf   dance.png

Notice that there are 3 spaces between each filename.

I want to do something along the sorts of:

  1. Assuming we start at the first character, advance until we reach a space.
  2. Copy everything up to that space into an array at index 0.
  3. Skip 2 spaces (to traverse the 3 space gap).
  4. Go until we hit a space and then copy that into array index 1.

I could do a hack job of this, just curious as to how some of the more advanced programmers would do this as I am here to learn.

回答1:

std::istringstream iss(the_array);
std::string f1, f2, f3, f4;
iss >> f1 >> f2 >> f3 >> f4;


标签: c++ parsing char