這是我的程序從文本文件中讀取數據並將其存儲到一個向量,即時通訊編輯有困難,任何建議將是偉大的。 編號喜歡在這個例子中調用年份和月份的所有數據。我希望它的東西簡單地錯過了。錯誤與讀取數據返回一個向量
#include <iostream>
#include <libscat.h>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
struct Weather
{
int year;
int month;
double tempmax;
double tempmin;
};
int main()
{
vector<Weather> data_weather;
string line;
std::ifstream myfile ("weatherdata.txt");
if (myfile.is_open())
{
while (getline(myfile, line))
{ int count = 0;
if (count > 8)
{
std::istringstream buffer(line);
int year, mm;
double tmax, tmin;
if (buffer >> year >> mm >> tmax >> tmin)
{
Weather objName = {year, mm, tmax, tmin};
data_weather.push_back(objName);
count++;
}
}
for (auto it = data_weather.begin(); it != data_weather.end(); it++){
std::cout << it->year << " " << it->month << std::endl;}
myfile.close();
}
else
{
cout << "unable to open file";
}
scat::pause("\nPress <ENTER> to end the program.");
return 0;
}
}
Post編譯器錯誤。還有'std :: vector','std :: string','std :: getline()'和'std :: cout'。 – hmjd 2013-04-04 10:45:27
「我有麻煩」是一個模糊的問題描述。你具體做什麼?當你這樣做時,究竟發生了什麼? – 2013-04-04 10:45:38
還有一個錯誤:期待一個聲明。它不會編譯,我基本上想讀取存儲在向量中的一些選定的數據。返回 – jaylad 2013-04-04 10:47:38