|
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <vector>
- #include <string>
- using namespace std;
- int main(int argc, char** argv)
- {
- /* Read data from point_right.csv */
- ifstream fin("..//GBPUSD60.csv"); // 打开文件流操作
- string line;
- while (getline(fin, line)) // 整行读取,换行符“\n”区分,遇到文件尾标志eof终止读取
- {
- cout << "原始字符串: " << line << endl; // 整行输出
- istringstream sin(line); // 将整行字符串line读入到字符串流istringstream中
- vector<string> Waypoints; // 声明一个字符串向量
- string info;
- while (getline(sin, info, ','))// 将字符串流sin中的字符读入到Waypoints字符串中,以逗号为分隔符
- {
- Waypoints.push_back(info); // 将刚刚读取的字符串添加到向量Waypoints中
- }
- string o_str = Waypoints[2]; //csv文件内容的第三列
- string c_str = Waypoints[3]; //csv文件内容的第四列
- string h_str = Waypoints[4]; //csv文件内容的第五列
- string l_str = Waypoints[5]; //csv文件内容的第六列
- string v_str = Waypoints[6]; //csv文件内容的第七列
- double open, close, high,low;
- int volume;
- stringstream so, sc, sh,sl, sv;
- so << o_str;
- sc << c_str;
- sh << h_str;
- sl << l_str;
- sv << v_str;
- so >> open;
- sc >> close;
- sh >> high;
- sl >> low;
- sv >> volume;
- cout << "open= " << open << " " << "close= " << close << " "
- << "high= " << high <<" "<<"low="<<low<<" "<<"volume="<<volume<< "\n\r"<<endl;
- //cout << "Read data done!" << endl;
- }
- return 0;
- }
复制代码
求高手指教,已经成功读取到数据了,为什么读到最后出现:vector subscript out of range
咱们的网站不支持上传csv文件,所以放在了百度网盘:
链接:https://pan.baidu.com/s/1zmGophz9b9-TBOplLfOAjA
提取码:tb5x
传不了 csv 可以给 csv 文件压缩一下,压缩成 zip 就可以啦
|
上一篇: WinHttp.WinHttpRequest.5.1在C++中该怎么使用?下一篇: 取出 mysql 数据库的值
|