C - 将文本文件读为一串单词,然后将字符串分为向量
C++ - Read a text file in as a string of words, then split the string into a vector
假设" grade.txt"的内容为:
David 99 94 95
Mike 91 84
John 100 85
Lexa 76 88 90 74 85 76
Paul 83 95
Ryan 71 72 85
Tommy 95 96
Joseph 100 83 85 86
Denise 100 90 76
Ava 80 90
文件的第一行用每个学生的名称表示。之后的上线是每个学生成绩的随机集合。
我的问题涉及我如何以单词字符串的形式读取文件,然后将字符串拆分为向量,以便我可以将每个元素组织到班级学生的正确位置中。如果有一种更简单的方法来实现这一目标,我也将不胜感激。谢谢您提供的任何帮助。
这是我的班级学生:
class Students {
public:
Students();
~Students();
private:
string name;
int grades;
};
您可以尝试boost :: split。例如:
//split strFileBuffer with space and get the string vector.
string strFileBuffer;
vector<string> strs;
boost::split(strs, strFileBuffer,boost::is_any_of(" "));
相关文章:
- C++为一串单词添加空格
- 为什么Visual Studio正在清除我的一串反斜杠
- 如何将内存中的位转换为一串和零?
- 如何返回一串字母数字字符中的最大值(例如-1A003B3)?
- 创建一个程序,该程序将一串数字作为输入,并输出偶数和奇数的总和
- C++ 如何对一串数字求平均值
- 从网络数据包复制一串 wchar 时访问冲突
- C - 将文本文件读为一串单词,然后将字符串分为向量
- 我如何在一串随机生成的字母I C 中查找一个单词
- 从一串数字C++创建一个数字序列
- 将一串十六进制存储到字符中
- 在另一个字符串中查找一串数字
- 将一串数字分解为26以下数字的计数方法
- 把一串单词解析成一组单词
- 将一串数字转换为整数向量 c++
- 将一串单词视为数组 (C++)
- 使用算术记数法横向排列一串字符
- 我有编译器的情况。当我运行代码来去除一串特殊字符时,它在一个编译器中运行,但在另一个编译器中不运行?
- 将一串数字转换为任何形式的整数
- 如何将数字"Bind"到一串单词/短语中,以便我可以循环调用它?