C++将csv文件数据读入数组中
来源:互联网 发布:python google语音api 编辑:程序博客网 时间:2024/05/18 08:33
将形如 1,2,3
4,5,6
7,8,9
的csv文件数据放入二维数组中。
#include <iostream> #include <string> #include <vector> #include <fstream> #include <sstream> using namespace std; int main() { // 写文件 //ofstream outFile; //outFile.open("data.csv", ios::out); // 打开模式可省略 //outFile << "name" << ',' << "age" << ',' << "hobby" << endl; //outFile << "Mike" << ',' << 18 << ',' << "paiting" << endl; //outFile << "Tom" << ',' << 25 << ',' << "football" << endl; //outFile << "Jack" << ',' << 21 << ',' << "music" << endl; //outFile.close(); // 读文件 ifstream inFile("E://1.txt", ios::in); string lineStr; vector<vector<string>> strArray; int array[3][3]; int i,j; i=0; char* end; if(inFile.fail()) cout<<"读取文件失败"<<endl; while (getline(inFile, lineStr)) { j=0; // 打印整行字符串 cout << lineStr << endl; // 存成二维表结构 stringstream ss(lineStr); string str; vector<string> lineArray; // 按照逗号分隔 while (getline(ss, str, ',')) { array[i][j]=static_cast<int>(strtol(str.c_str(),&end,10)); //string -> int j++; } i++; // strArray.push_back(lineArray); } for(int i=0;i<3;i++) { for(int j=0;j<3;j++) cout<<array[i][j]; cout<<endl; } getchar(); return 0; }
阅读全文
0 0
- C++将csv文件数据读入数组中
- 将csv文件读入到数组里
- Python:将文件中的数据读入到数组中
- 将一个文件 读入一个数组中
- C语言:从文件中读入数据
- 抓取数据为json文件,读入csv
- C语言从txt文件中逐行读入数据存到数组中
- 用C语言将文件内容读入数组
- 用C语言实现将一个文件读入内存中
- c#将DataTable中数据写入到CSV文件中
- java将数据写入csv文件,从csv文件中读取数据
- 将txt文本读入C中(txt数据量大),将C中数据写入txt
- 如何将.txt文件读入到数组
- 将DataSet数据集导入CSV后缀文件中
- 将Csv文件数据导入到数据库表中
- 如何将数据库的数据导入到csv文件中
- java将数据写入到csv文件中
- 从文件中读入数据
- 【软测】设计scp的测试用例
- 并发插入引发的死锁问题排查
- C++风格_整型
- vuex 使用整理
- 函数的递归
- C++将csv文件数据读入数组中
- hiho第173周 A Game (区间DP)
- gsoap_2.8.33.zip安装与编译
- 前端开发规范整理
- 深度学习的简单理解
- Lua开源库 lfs的介绍与使用
- [VijosP1737][NOIp2011tg D1T2]选择客栈
- ccf 201509-2日期计算
- spring中@value注解需要注意