Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

cin.ignore

[es] :: C programiranje :: cin.ignore

[ Pregleda: 1319 | Odgovora: 1 ]

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Pretender

Član broj: 12407
Poruke: 100
*.beotel.net



Profil

icon cin.ignore22.11.2003. u 20:34

Jedno `malo` pitanje:

Code:

1:     #include <fstream.h>
2:     int main()
3:     {
4:        char fileName[80];
5:        char buffer[255];    // for user input
6:        cout << "File name: ";
7:        cin >> fileName;
8:
9:        ofstream fout(fileName);  // open for writing
10:       fout << "This line written directly to the file...\n";
11:       cout << "Enter text for the file: ";
12:       cin.ignore(1,'\n');  // eat the newline after the file name
13:       cin.getline(buffer,255);  // get the user's input
14:       fout << buffer << "\n";   // and write it to the file
15:       fout.close();             // close the file, ready for reopen


Citat:
The newline character left over from the user's input of the filename is eaten on line 12, and the user's input is stored into buffer on line 13.



Ne vidim gde je to ostavljen karakter \n posle unosa filename ?


Tx
22.11.2003. u 20:34 

leka
Dejan Lekić
senior software engineer, 3Developers Ltd.
London, UK

Član broj: 234
Poruke: 2530
*.telia.com

Sajt: dejan.lekic.org


Profil

icon Re: cin.ignore15.12.2003. u 13:48
getline() bi trebalo da u bafer strpa i '\n' ...
Dejan Lekic
software engineer, MySQL/PgSQL DBA, sysadmin
15.12.2003. u 13:48 

[es] :: C programiranje :: cin.ignore

[ Pregleda: 1319 | Odgovora: 1 ]

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.