Article View: pl.comp.lang.c
Article #309648Re: Czytanie z pliku wiersza do stringa zamiast bufora
From: 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**
Technical Details
Message-ID:
<slrnp7etro.e5i.amok@vegeta.utgard.biz>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mailReferences:
<p57qu7$vtj$1@node1.news.atman.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: Marcin Konarski <amok@codestation.org> Newsgroups: pl.comp.lang.c Subject: Re: Czytanie z pliku wiersza do stringa zamiast bufora Date: Sun, 4 Feb 2018 21:13:28 +0000 (UTC) Organization: ATMAN - ATM S.A. Lines: 35 Message-ID: <slrnp7etro.e5i.amok@vegeta.utgard.biz> References: <p57qu7$vtj$1@node1.news.atman.pl> Reply-To: marcin.konarski+usenet.cutit@gmail.com NNTP-Posting-Host: 178-36-16-12.adsl.inetia.pl Mime-Version: 1.0 X-Trace: node2.news.atman.pl 1517778808 28625 178.36.16.12 (4 Feb 2018 21:13:28 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Sun, 4 Feb 2018 21:13:28 +0000 (UTC) User-Agent: slrn/1.0.3 (Linux) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit