69,371
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include "stdio.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s="12 13 14.5 16 18";
vector<double> fvec;
size_t npos=s.find(" ");
size_t ipos=0;
while(npos!=string::npos)
{
s.substr(ipos,npos);
fvec.push_back(atof(s.substr(ipos,npos).c_str()));
ipos=npos;
npos=s.find(" ",ipos+1);
}
vector<double>::iterator itor;
itor=fvec.begin();
while(itor!=fvec.end())
{
cout<<*itor++<<endl;
}
return 0;
}
istringstream iss(s);
vector<double> vd;
double temp;
iss >> temp;
while (iss)
{
vd.push_back(temp);
iss >> temp;
}
数量可由 vd.size()获得
判断text文件空行,用getline(cin,string)读取,判断string == ""就是空行。
1 strtok();
2 atof();
double atof(string);