Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

fstream zapis nie działa

Ostatnio zmodyfikowano 2011-01-21 23:42
Autor Wiadomość
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:
C/C++
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;

//ZMIENNE*************************************
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()
{
   
    // PLIKI Z DANYMI ***************************
    fstream plik_name( "name.txt" );
    fstream plik_surname( "surname.txt" );
    fstream plik_phone_number( "phone number.txt" );
    //*******************************************
   
    start:
    //MENU GLOWNE********************************
    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:
        {
            //DODAWANIE OSOBY DO LISTY*********************
            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 );
}
P-26769
ison
» 2011-01-21 17:32:07
C/C++
fstream plik_name( "name.txt", ios::out );
lub
C/C++
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)
P-26770
Bartaz
Temat założony przez niniejszego użytkownika
» 2011-01-21 17:50:15
1.Nic nie dalo.
2.Kod sie kompiluje
P-26771
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/)

C/C++
plik_name << name[ name_person ] << endl;
P-26772
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 ;[
P-26774
Elaine
» 2011-01-21 18:38:14
To się w ogóle kompiluje bez
#include <string>
? U mnie jakoś nie bardzo.
P-26776
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.
P-26778
dmx81
» 2011-01-21 23:42:34
az dziwne, ze nie "nakrzyczeli" o uzywanie "goto" i brak default dla switcha ;)
P-26815
« 1 »
  Strona 1 z 1