利用vector对文件的内容进行按行存储并输出
2012-10-22 08:52
295 查看
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main(void)
{
ifstream fp("I:\\temp.txt");
vector< vector<double> > tmp;
// string str;
char str[100];
double i;
char *ch,*ch1;
int num;
while(!fp.eof())
{
vector<double> m1;
// getline(fp,str,'\n');
fp.getline(str,100);
num = fp.gcount();
cout<<"num = "<<num<<endl;
// ch1 = const_cast<char *>(str.c_str());
ch1 = const_cast<char *>(str);
ch = strtok(ch1," ");
m1.push_back(atof(ch));
vector<double>::iterator c22 = m1.begin();
while(ch)
{
ch = strtok(NULL," ");
m1.push_back(atof(ch));
}
m1.pop_back();
tmp.push_back(m1);
}
vector< vector<double> >::iterator cnt = tmp.begin();
vector<double> v1 = *(cnt);
while(cnt != tmp.end())
{
vector<double>::iterator cnt1 = v1.begin();
while(cnt1 != v1.end())
{
cout<<*cnt1<<" ";
cnt1++;
}
cnt++;
cout<<endl;
v1 = *cnt;
}
return 0;
}
相关文章推荐
- 存储过程导出csv文件,利用xml对csv文件内容进行批量处理
- 数据加载、存储与文件格式 利用Python进行数据分析 第6章
- Python按行输出文件内容详解及延伸
- 遍历文件夹下各个文件,然后读出每个文件的内容,并对内容进行过滤输出
- 利用Shell脚本进行文件内容去重
- 利用python进行数据分析之数据加载存储与文件格式
- 利用stringstream将文件中的内容一行行读取并输出出来
- 利用C#控制台输出txt文件的内容(一行行来的)
- 利用Shell脚本进行文件内容去重
- 利用vector进行图的存储
- 如何先搜索文件然后在文件中搜索具体内容进行输出?
- 一个简单的利用ini配置文件以及用户输入的交互进行文件夹内容拷贝的批处理文件脚本的实现
- java按行读取文件内容并输出
- 如何利用AJAX进行文件的上传,并对上传内容进行限制,在项目中总会遇见这样的问题,下面就为大家举个栗子。 HTML代码 <form id="uploadForm" enctype="multipar
- Android 存储文件方式之一---SharedPreferences 内容提供者,以xml 的方式进行数据 存储。是一种轻量级的文件数据存储
- c++中如何利用vector fstream进行文件的读取
- 8.9 编写函数打开文件用于输入,将文件内容读入 string 类型的 vector 容器,每一行存储为该容器对象 的一个元素。8.10 重写上面的程序,把文件中的每个单词存储为 容器的一个元素
- 使用文件进行数据存储及读取文件内容
- visual studio中利用txt文件中的内容进行输入(实参传递)
- C++ 按行读取文件并按空格将数据存储为vector