code:
std::cout << "enter file to write\n> "; std::string filename; std::cin >> filename; std::ofstream myfile(filename, std::ofstream::app | std::ofstream::binary); if (myfile){ std::streamsize size = sizeof(city); myfile.write(temp, size); std::cout << "SAVED!\n"; } myfile.close(); City structure fields:
struct city { char name[32]; int citizens; float territory; int startyear; int schools; }; mistake:
test.cpp: In function 'int main()': test.cpp:61:36: error: no matching function for call to 'std::basic_ofstream<char>::write(city&, std::streamsize&)' myfile.write(temp, size); ^ In file included from /usr/include/c++/7/ostream:693:0, from /usr/include/c++/7/iostream:39, from test.cpp:2: /usr/include/c++/7/bits/ostream.tcc:182:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::write(const _CharT*, std::streamsize) [with _CharT = char; _Traits = std::char_traits<char>; std::streamsize = long int] basic_ostream<_CharT, _Traits>:: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/7/bits/ostream.tcc:182:5: note: no known conversion for argument 1 from 'city' to 'const char*'