![]() |
#2
gmac2011-03-16 13:25
|

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <map>
using namespace std;
int main()
{
string word;
vector<string> data;
ifstream infile;
infile.open("05.txt");
if(!infile)
{
cerr << "can't open the file"<<endl;
}
int count = 1;
while(infile >> word)
{
if(count%13) //改为14后图以贴出
{
data.push_back(word);
count=count+1;
}
else{
cout<<data[12]<<endl;//想输出最后一项却老是报错出界。
data.clear();
infile.clear();
count=1;
}
}
system("pause");
}
希望大家帮我看看。#include <string>
#include <vector>
#include <fstream>
#include <map>
using namespace std;
int main()
{
string word;
vector<string> data;
ifstream infile;
infile.open("05.txt");
if(!infile)
{
cerr << "can't open the file"<<endl;
}
int count = 1;
while(infile >> word)
{
if(count%13) //改为14后图以贴出
{
data.push_back(word);
count=count+1;
}
else{
cout<<data[12]<<endl;//想输出最后一项却老是报错出界。
data.clear();
infile.clear();
count=1;
}
}
system("pause");
}
文件的格式
05.txt
TC ALGOPARK 918034.6970 -4346132.2810 4561971.1810 AZEL .00000 7282
TV ALGOPARK -.0157 -.0036 0.0039 最后这个数。。。。
TC AUS_NEW -3530219.3810 4118797.5280 3344015.8070 AZEL .00000 7348
TV AUS_NEW -.0262 -.0046 -.0138
TC FORTLEZA 4985370.0380 -3955020.3390 -428472.2450 AZEL .00000 7297
TV FORTLEZA -.0016 -.0045 0.0131
TC GILCREEK -2281547.4360 -1453645.2050 5756993.1460 X-Y1 7.31520 7225
TV GILCREEK -.0168 0.0030 -.0119
TC HARTRAO 5085442.7790 2668263.5440 -2768696.9630 EQUA 6.69530 7232
TV HARTRAO -.0002 0.0193 0.0173
先谢谢大家了!
另外:关于用C++进行文件输出如何进行格式控制,感觉没有C的那种%简单。。用C++如何控制呢?
帮忙写个代码,输出到06.txt,格式和05.txt一样。。
只有本站会员才能查看附件,请 登录
分不多重要的是以助人为乐。对吧!?

按楼下的改后
只有第一个数值输出的是正确的,图已贴出
[ 本帖最后由 gmac 于 2011-3-16 17:35 编辑 ]