fstream zapis nie działa
Ostatnio zmodyfikowano 2011-01-21 23:42
Bartaz Temat założony przez niniejszego użytkownika |
fstream zapis nie działa » 2011-01-21 17:23:45 Witam pisze sobie ksiazke telefoniczna ale nie zapisuja sie dane do pliku znaczy wczesniej sie zapisywaly dodalem pare innych rzeczy do zapisania nie dzialalo coflem zmiany ale i tak nie dziala pozamienialem zeby plik nie byl tylko do odczytu. Kod: #include <iostream> #include <fstream> #include <conio.h> using namespace std;
int menu_glowne; string name[ 30 ]; string surname[ 30 ]; int phone_number[ 30 ]; int phone_number_person = 1; int name_person = 1; int surname_person = 1;
int main() { fstream plik_name( "name.txt" ); fstream plik_surname( "surname.txt" ); fstream plik_phone_number( "phone number.txt" ); start: cout << "[1]-Add person " << endl; cout << "" << endl; cout << "[2]-Show the list of persons" << endl; cout << "" << endl; cout << "[3]-Delete the list of persons" << endl; cout << "" << endl; cout << "[4]-Search" << endl; cout << "" << endl; cout << "[5]-Exit" << endl; cin >> menu_glowne; switch( menu_glowne ) { case 1: { system( "cls" ); cout << "Enter the name of the person" << endl; cin >> name[ name_person ]; cout << name[ name_person ] << endl; plik_name << name[ name_person ]; name_person++; cout << "Enter the surname of the person" << endl; cin >> surname[ surname_person ]; cout << surname[ surname_person ] << endl; plik_surname << surname[ surname_person ]; surname_person++; cout << "Enter the phone number of the person" << endl; cin >> phone_number[ phone_number_person ]; cout << phone_number[ phone_number_person ] << endl; plik_phone_number << phone_number[ phone_number_person ]; phone_number_person++; break; } } goto start; getch(); return( 0 ); }
|
|
ison |
» 2011-01-21 17:32:07 fstream plik_name( "name.txt", ios::out );
lub ofstream plik_name( "name.txt" );
już pomijając sam fakt, że Twój kod się w ogóle nie kompiluje (brakuje biblioteki cstdlib do funkcji system) |
|
Bartaz Temat założony przez niniejszego użytkownika |
» 2011-01-21 17:50:15 1.Nic nie dalo. 2.Kod sie kompiluje |
|
ison |
» 2011-01-21 18:07:19 1. U mnie działa... (nie zapomniałeś przypadkiem o nowej linii na końcu zapisywanego tekstu?) 2. Nie kompiluje według aktualnych standardów, to że ty masz starego Deva, który nie jest już rozwijany od dawna, ze starym kompilatorem to już nie moja wina ( http://www.cplusplus.com/reference/clibrary/cstdlib/system/) plik_name << name[ name_person ] << endl;
|
|
Bartaz Temat założony przez niniejszego użytkownika |
» 2011-01-21 18:19:14 Dzieki dziala ;p Tak mam deva ale juz sie sciaga od jakies 1,5 visual jeszcze 7h do sciagnieca ;[ |
|
Elaine |
» 2011-01-21 18:38:14 To się w ogóle kompiluje bez #include <string> ? U mnie jakoś nie bardzo. |
|
ison |
» 2011-01-21 18:57:51 nawet nie zwróciłem uwagi, dziwne jest to, że w najnowszej paczce Code::Blocks ten program po dołączeniu cstdlib kompiluje się bez problemu. |
|
dmx81 |
» 2011-01-21 23:42:34 az dziwne, ze nie "nakrzyczeli" o uzywanie "goto" i brak default dla switcha ;) |
|
« 1 » |