excitatory
Newbie | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Ребята, подскажите пожалуйста почему не работают функции write и read для вывода потока в файл. вроде бы ошибок нет, а в файле кракозябры, а int вообще отсутствует. не пойму, где косяк. запускал на Dev c++ и Visual c++, один фиг. посмотрите код, плиз Код: #include<iostream> #include<fstream> #include<windows.h> #include<conio.h> class Emploee { public: char name[30]; int age; Emploee(char* name = " ", int age = 0); }; Emploee::Emploee(char* name, int age) { strcpy(Emploee::name, name); Emploee::age = age; } void Write() { Emploee a("Джон Силвер", 50); Emploee b("Врунгель", 15); std::ofstream fout; fout.open("test.txt"); fout.write((char*)&a, sizeof(a)); fout<<std::endl; fout.write((char*)&b, sizeof(b)); fout.close(); fout.clear(); } int main(int argc, char* argv[]) { SetConsoleCP(1251); SetConsoleOutputCP(1251); std::cout<<"\n\tзапись в файл write and read\n"; Write(); _getch(); return 0; } |
|