仅读取文本文件中的数字并存储在数组中.之后,读取第一行来存储在数组中
C++: Reading only numbers in text file and store in array. After, reading the first row to store in array too
我有"Data.txt"的内容
Row 1: ACB MMM
Row 2: Date High Low Open Close Volume Adjusted Close Date High Low Open Close Volume Adjusted Close
Row 3: 40000 10 12 16 17 1500 17.2 40002 12 11 14 12 1200 12.2
Row 4: 40001 17.2 14 15 16 2500 18 40003 13.2 12 13 13 2300 13
注意:第一行和第二行只能是字符串,每个字符串用制表符分隔。从第三行开始,只有数字,每个字符串用制表符分隔。
我想从第3行读取到存储在数组"data"和读取第1行存储在数组"symbol"。
谢谢你的帮助。
我的代码如下链接:http://www.mediafire.com/view/qfxtvj8sr022rff/Code.txt
使用std::getline
逐行读取文件
#include <iostream>
#include <fstream>
#include <string>
. . .
ifstream file("Data.txt");
string line;
while (getline(file, line)) {
. . .
}
使用std::stringstream
从字符串
#include <sstream>
stringstream ss(line);
ss >> . . .;
相关文章:
- 使用无符号字符数组有效存储内存
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 在c++中获取两个大int,并将它们存储在数组中
- 使用 Xcode 将双精度存储在数组C++中
- 访问表示 2D 矩阵的 1D 存储数组
- 从输入文件读取整数,仅存储数组C 中的唯一整数
- 如何在队列中存储数组
- 按列主要顺序迭代行大量存储数组
- 如何使存储数组的二进制搜索稳定
- 将行中的字段从textfile中更改为存储数组,而不是重新编写文件
- 存储数组索引值C++
- 存储数组的地方,如果我在返回后声明它
- 缺少存储数组地址的内存
- 使用static在函数中存储数组各个组件的值
- 如何存储数组的每个相邻子数组的和
- 在c++中存储数组映射
- 存储数组的地址列表,以解析原始的非终止文本
- 用于存储数组的字符串
- c++存储数组下一个位置的地址
- 在 for 循环中创建和存储数组