Thread View: pl.comp.lang.c
2 messages
2 total messages
Started by Borneq
Sun, 04 Feb 2018 20:37
Czytanie z pliku wiersza do stringa zamiast bufora
Author: Borneq
Date: Sun, 04 Feb 2018 20:37
Date: Sun, 04 Feb 2018 20:37
21 lines
1306 bytes
1306 bytes
W Google gdy szukam czytanie pliku tekstowego linia po linii, otrzymuję
coś takiego:
#include <iostream>
#include <fstream>
using namespace std;
.....
ifstream infile(filename);
string line;
char buf[4096];
while (!infile.eof())
{
infile.getline(buf, 4096);
line = buf;
}
Mam bufor, spory, ale może być niewystarczający, gdy plik to głównie
jedna długa linia (np. html, xml)
Czy jest możliwość czytania do stringa zamiast bufora?
Re: Czytanie z pliku wiersza do stringa zamiast bufora
Author: Marcin Konarski
Date: Sun, 04 Feb 2018 21:13
Date: Sun, 04 Feb 2018 21:13
35 lines
1706 bytes
1706 bytes
On Sun, 4 Feb 2018 21:37:26 +0100,
Borneq <borneq@antyspam.hidden.pl> wrote:
> W Google gdy szukam czytanie pliku tekstowego linia po linii, otrzymuję
> coś takiego:
> #include <iostream>
> #include <fstream>
>
> using namespace std;
>
>
> .....
> ifstream infile(filename);
> string line;
> char buf[4096];
> while (!infile.eof())
> {
> infile.getline(buf, 4096);
> line = buf;
> }
>
> Mam bufor, spory, ale może być niewystarczający, gdy plik to głównie
> jedna długa linia (np. html, xml)
> Czy jest możliwość czytania do stringa zamiast bufora?
ifstream infile( filename );
string line;
while ( getline( infile, line ).good() ) {
doSomething( line );
}
--
Amok Huginnsson
GCS d? s:+ a C+++$() UBLS++++$ P L++++$ E---
W++(-) N++ w--- O M- V- PS+ PE++ Y PGP
t--- 5-- X- R !tv b++ DI+++ D+ G e* h+ r- y**
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads