本文介绍了从字符数组解析文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我道歉,如果这之前已被问过,但我试图解析一个字符数组,我可以获得文件名。
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
请注意,每个文件名之间有3个空格。
Notice that there are 3 spaces between each filename.
- 假设我们从第一个字符开始,直到我们到达一个空格。
- 将所有空间复制到索引为0的数组中。
- 跳过2个空格(以遍历3个空格间隔)。
- 直到我们击中一个空格,然后将其复制到数组索引1中。
- Assuming we start at the first character, advance until we reach a space.
- Copy everything up to that space into an array at index 0.
- Skip 2 spaces (to traverse the 3 space gap).
- Go until we hit a space and then copy that into array index 1.
我可以做一个hack工作
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.
推荐答案
std::istringstream iss(the_array);
std::string f1, f2, f3, f4;
iss >> f1 >> f2 >> f3 >> f4;
这篇关于从字符数组解析文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!