ベクトルvの内容をファイルに書きたいと思います。問題は、コンテンツではなくアドレスがテキストファイル内に配置されることです。ベクトルデータをファイルに書き込むC++の問題
私はエラーを取得する& POSの*のPOSインプレース書く:エラーC2679:バイナリ「< <」:何のオペレータがどのよう
型「エントリー」の右辺のオペランドをとる見つからなかったがそれは正しい?
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <limits>
/*
Data.txt
John
6543
23
Max
342
2
A Team
5645
23
*/
struct entry
{
// passengers data
std::string name;
int weight; // kg
std::string group_code;
};
void reservations(std::vector<entry> v)
{
std::ofstream outfile;
outfile.clear();
outfile.open("reservations.txt");
// print data in vector
std::vector<entry>::iterator pos;
for (pos = v.begin(); pos!= v.end();++pos)
{
outfile << &pos << std::endl;
std::cout << &pos << std::endl;
}
outfile.close();
}
entry read_passenger(std::ifstream &stream_in)
{
entry passenger;
if (stream_in)
{
std::getline(stream_in, passenger.name);
stream_in >> passenger.weight;
stream_in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::getline(stream_in, passenger.group_code);
stream_in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return passenger;
}
return passenger;
}
int main(void)
{
std::ifstream stream_in("data.txt");
std::vector<entry> v; // contains the reservations
std::vector<entry> a; // contains the cancellations
const int limit_total_weight = 10000; // kg
int total_weight = 0; // kg
entry current;
while (stream_in)
{
current = read_passenger(stream_in);
if (total_weight + current.weight >= limit_total_weight)
{
// push data (cancellations) to vector
a.push_back(current);
}
else
{
total_weight = total_weight + current.weight;
// push data (reservations) to vector
v.push_back(current);
}
}
reservations(v); // write reservations to file
std::cout << "Rest " << limit_total_weight - total_weight << "kg" <<std::endl;
return 0;
}
申し訳ありませんが、私はC++の初心者です!それはどういう意味ですか? – burner007