Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8563 > unrolled thread
| Started by | arnuld <sunrise@invalid.address> |
|---|---|
| First post | 2011-08-08 13:15 +0000 |
| Last post | 2011-08-12 15:56 -0500 |
| Articles | 20 on this page of 31 — 11 participants |
Back to article view | Back to comp.lang.c++
reading a file into std::string arnuld <sunrise@invalid.address> - 2011-08-08 13:15 +0000
Re: reading a file into std::string Marc <marc.glisse@gmail.com> - 2011-08-08 13:40 +0000
Re: reading a file into std::string Sam <sam@email-scan.com> - 2011-08-08 08:58 -0500
Re: reading a file into std::string Sam <sam@email-scan.com> - 2011-08-08 09:05 -0500
Re: reading a file into std::string red floyd <no.spam.here@its.invalid> - 2011-08-08 13:23 -0700
Re: reading a file into std::string arnuld <sunrise@invalid.address> - 2011-08-09 05:13 +0000
Re: reading a file into std::string red floyd <no.spam.here@its.invalid> - 2011-08-08 23:12 -0700
Re: reading a file into std::string arnuld <sunrise@invalid.address> - 2011-08-09 06:45 +0000
Re: reading a file into std::string red floyd <no.spam.here@its.invalid> - 2011-08-09 09:26 -0700
Re: reading a file into std::string arnuld <sunrise@invalid.address> - 2011-08-10 10:58 +0000
Re: reading a file into std::string "Bo Persson" <bop@gmb.dk> - 2011-08-10 16:19 +0200
Re: reading a file into std::string red floyd <no.spam.here@its.invalid> - 2011-08-10 10:06 -0700
Re: reading a file into std::string red floyd <no.spam.here@its.invalid> - 2011-08-09 09:28 -0700
Re: reading a file into std::string red floyd <no.spam.here@its.invalid> - 2011-08-09 09:33 -0700
Re: reading a file into std::string arnuld <sunrise@invalid.address> - 2011-08-10 12:13 +0000
Re: reading a file into std::string Nobody <nobody@nowhere.com> - 2011-08-11 08:57 +0100
Re: reading a file into std::string "Bo Persson" <bop@gmb.dk> - 2011-08-11 12:51 +0200
Re: reading a file into std::string Nobody <nobody@nowhere.com> - 2011-08-12 05:00 +0100
Re: reading a file into std::string Nana J. Osei <mppccf0987@att.net> - 2011-08-13 23:18 +0000
Re: reading a file into std::string Sam <sam@email-scan.com> - 2011-08-13 20:58 -0500
Re: reading a file into std::string Juha Nieminen <nospam@thanks.invalid> - 2011-08-09 11:26 +0000
Re: reading a file into std::string Marc <marc.glisse@gmail.com> - 2011-08-09 12:54 +0000
Re: reading a file into std::string Juha Nieminen <nospam@thanks.invalid> - 2011-08-09 16:33 +0000
Re: reading a file into std::string Marc <marc.glisse@gmail.com> - 2011-08-09 16:47 +0000
Re: reading a file into std::string red floyd <no.spam.here@its.invalid> - 2011-08-09 11:27 -0700
Re: reading a file into std::string Joshua Maurice <joshuamaurice@gmail.com> - 2011-08-11 15:34 -0700
Re: reading a file into std::string Juha Nieminen <nospam@thanks.invalid> - 2011-08-12 05:47 +0000
Re: reading a file into std::string arnuld <sunrise@invalid.address> - 2011-08-09 12:57 +0000
Re: reading a file into std::string Joshua Maurice <joshuamaurice@gmail.com> - 2011-08-11 15:40 -0700
Re: reading a file into std::string Jean-Luc Romano <jl_post@hotmail.com> - 2011-08-12 11:28 -0700
Re: reading a file into std::string Lynn McGuire <lmc@winsim.com> - 2011-08-12 15:56 -0500
Page 1 of 2 [1] 2 Next page →
| From | arnuld <sunrise@invalid.address> |
|---|---|
| Date | 2011-08-08 13:15 +0000 |
| Subject | reading a file into std::string |
| Message-ID | <4e3fe183$0$316$14726298@news.sunsite.dk> |
I want to read a file into std::string. I am basically a C Programmer so
it was quite hard for me to understand how to do it in C++. I did C++
long time back (if you guys remember my name but I do remember Shiva and
Victor Bazarov and others).
I googled for it and this is the best what I could come up with. Do you
guys have any suggestion for improvement ? and whether this is really a
correct C++ program. (Compiled with "g++ -ansi -pedantic -Wall -Wextra")
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string my_contents, tmp_contents;
std::ifstream my_file("reference.cpp");
if(!my_file)
{
std::cerr << "Error Opening file" << std::endl;
exit(EXIT_FAILURE);
}
while(my_file)
{
std::getline(my_file, tmp_contents);
my_contents += tmp_contents;
my_contents += "\n";
}
std::cout << "String contents are: "<< "\n"
<< my_contents << std::endl;
my_file.close();
return 0;
}
-- arnuld
www.LispMachine.Wordpress.com
[toc] | [next] | [standalone]
| From | Marc <marc.glisse@gmail.com> |
|---|---|
| Date | 2011-08-08 13:40 +0000 |
| Message-ID | <j1op04$67t$1@news-rocq.inria.fr> |
| In reply to | #8563 |
arnuld wrote:
> I want to read a file into std::string. I am basically a C Programmer so
> it was quite hard for me to understand how to do it in C++. I did C++
> long time back (if you guys remember my name but I do remember Shiva and
> Victor Bazarov and others).
[...]
> std::string my_contents, tmp_contents;
> std::ifstream my_file("reference.cpp");
> if(!my_file)
> {
> std::cerr << "Error Opening file" << std::endl;
> exit(EXIT_FAILURE);
> }
>
> while(my_file)
> {
> std::getline(my_file, tmp_contents);
> my_contents += tmp_contents;
> my_contents += "\n";
> }
You might as well use std::getline(my_file, my_contents, '\0'),
assuming there is no null character in your file. Not that it is a
good solution, but at least you don't have a loop.
[toc] | [prev] | [next] | [standalone]
| From | Sam <sam@email-scan.com> |
|---|---|
| Date | 2011-08-08 08:58 -0500 |
| Message-ID | <cone.1312811905.617876.25291.500@monster.email-scan.com> |
| In reply to | #8563 |
[Multipart message — attachments visible in raw view] — view raw
arnuld writes:
> I want to read a file into std::string. I am basically a C Programmer so
> it was quite hard for me to understand how to do it in C++. I did C++
> long time back (if you guys remember my name but I do remember Shiva and
> Victor Bazarov and others).
>
> I googled for it and this is the best what I could come up with. Do you
> guys have any suggestion for improvement ? and whether this is really a
> correct C++ program. (Compiled with "g++ -ansi -pedantic -Wall -Wextra")
Your program is basically a C program. Here's a C++ program.
#include <iostream>
#include <fstream>
#include <sstream>
int main()
{
std::ostringstream o;
o << std::ifstream("reference.cpp").rdbuf();
std::string my_contents= o.str();
return 0;
}
>
>
>
> #include <iostream>
> #include <fstream>
> #include <string>
>
>
> int main()
> {
> std::string my_contents, tmp_contents;
> std::ifstream my_file("reference.cpp");
> if(!my_file)
> {
> std::cerr << "Error Opening file" << std::endl;
> exit(EXIT_FAILURE);
> }
>
> while(my_file)
> {
> std::getline(my_file, tmp_contents);
> my_contents += tmp_contents;
> my_contents += "\n";
> }
>
> std::cout << "String contents are: "<< "\n"
> << my_contents << std::endl;
>
> my_file.close();
>
> return 0;
> }
>
>
>
>
>
> -- arnuld
> www.LispMachine.Wordpress.com
[toc] | [prev] | [next] | [standalone]
| From | Sam <sam@email-scan.com> |
|---|---|
| Date | 2011-08-08 09:05 -0500 |
| Message-ID | <cone.1312812316.772351.25291.500@monster.email-scan.com> |
| In reply to | #8565 |
[Multipart message — attachments visible in raw view] — view raw
Sam writes:
> arnuld writes:
>
>> I want to read a file into std::string. I am basically a C Programmer so
>> it was quite hard for me to understand how to do it in C++. I did C++
>> long time back (if you guys remember my name but I do remember Shiva and
>> Victor Bazarov and others).
>>
>> I googled for it and this is the best what I could come up with. Do you
>> guys have any suggestion for improvement ? and whether this is really a
>> correct C++ program. (Compiled with "g++ -ansi -pedantic -Wall -Wextra")
>
> Your program is basically a C program. Here's a C++ program.
>
> #include <iostream>
> #include <fstream>
> #include <sstream>
>
> int main()
> {
> std::ostringstream o;
>
> o << std::ifstream("reference.cpp").rdbuf();
>
> std::string my_contents= o.str();
>
> return 0;
> }
… Or, here's a slightly more efficient version.
#include <iostream>
#include <fstream>
#include <iterator>
#include <algorithm>
int main()
{
std::string my_contents;
std::copy(std::istreambuf_iterator<char>(std::ifstream("reference.cpp").rdbuf()),
std::istreambuf_iterator<char>(),
std::back_insert_iterator<std::string>(my_contents));
return 0;
}
>
>>
>>
>>
>> #include <iostream>
>> #include <fstream>
>> #include <string>
>>
>>
>> int main()
>> {
>> std::string my_contents, tmp_contents;
>> std::ifstream my_file("reference.cpp");
>> if(!my_file)
>> {
>> std::cerr << "Error Opening file" << std::endl;
>> exit(EXIT_FAILURE);
>> }
>>
>> while(my_file)
>> {
>> std::getline(my_file, tmp_contents);
>> my_contents += tmp_contents;
>> my_contents += "\n";
>> }
>>
>> std::cout << "String contents are: "<< "\n"
>> << my_contents << std::endl;
>>
>> my_file.close();
>>
>> return 0;
>> }
>>
>>
>>
>>
>>
>> -- arnuld
>> www.LispMachine.Wordpress.com
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-08-08 13:23 -0700 |
| Message-ID | <j1pgkl$q92$1@dont-email.me> |
| In reply to | #8566 |
On 8/8/2011 7:05 AM, Sam wrote:
> Sam writes:
>
>> arnuld writes:
>>
>>> I want to read a file into std::string. I am basically a C Programmer so
>>> it was quite hard for me to understand how to do it in C++. I did C++
>>> long time back (if you guys remember my name but I do remember Shiva and
>>> Victor Bazarov and others).
>>>
>>> I googled for it and this is the best what I could come up with. Do you
>>> guys have any suggestion for improvement ? and whether this is really a
>>> correct C++ program. (Compiled with "g++ -ansi -pedantic -Wall -Wextra")
>>
>> Your program is basically a C program. Here's a C++ program.
>>
>> #include <iostream>
>> #include <fstream>
>> #include <sstream>
>>
>> int main()
>> {
>> std::ostringstream o;
>>
>> o << std::ifstream("reference.cpp").rdbuf();
>>
>> std::string my_contents= o.str();
>>
>> return 0;
>> }
>
> … Or, here's a slightly more efficient version.
>
> #include <iostream>
> #include <fstream>
> #include <iterator>
> #include <algorithm>
>
> int main()
> {
> std::string my_contents;
>
> std::copy(std::istreambuf_iterator<char>(std::ifstream("reference.cpp").rdbuf()),
>
> std::istreambuf_iterator<char>(),
> std::back_insert_iterator<std::string>(my_contents));
>
> return 0;
> }
>
>
Avoid the copy.
#include <iostream>
#include <fstream>
#include <string>
#include <iterator>
int main()
{
// note: extra parens on the constructor args to
// avoid potential "Most Vexing Parse" issues
std::string my_contents(
std::istreambuf_iterator<char>(
(std::ifstream("reference.cpp").rdbuf())),
(std::istreambuf_iterator<char>()));
}
[toc] | [prev] | [next] | [standalone]
| From | arnuld <sunrise@invalid.address> |
|---|---|
| Date | 2011-08-09 05:13 +0000 |
| Message-ID | <4e40c1f8$0$310$14726298@news.sunsite.dk> |
| In reply to | #8570 |
> On Mon, 08 Aug 2011 13:23:49 -0700, red floyd wrote:
> Avoid the copy.
>
>
> #include <iostream>
> #include <fstream>
> #include <string>
> #include <iterator>
>
> int main()
> {
> // note: extra parens on the constructor args to
> // avoid potential "Most Vexing Parse" issues
> std::string my_contents(
> std::istreambuf_iterator<char>(
> (std::ifstream("reference.cpp").rdbuf())),
> (std::istreambuf_iterator<char>()));
> }
Can you please tell me in brief how it works. 2nd, you said "Avoid the
copy", so your program does not copy ?
All I can see is its a template. What about error checking whether file
was opened successfully or not, we are nto even closing the file after we
finish ? I have Stroustrup 3/e in my hands, checking out what rdbuf()
does from section 21.6.3, page 644.
--
-- arnuld
www.LispMachine.Wordpress.com
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-08-08 23:12 -0700 |
| Message-ID | <j1qj58$ue4$1@dont-email.me> |
| In reply to | #8577 |
On 8/8/2011 10:13 PM, arnuld wrote:
>> On Mon, 08 Aug 2011 13:23:49 -0700, red floyd wrote:
>
>> Avoid the copy.
>>
>>
>> #include<iostream>
>> #include<fstream>
>> #include<string>
>> #include<iterator>
>>
>> int main()
>> {
>> // note: extra parens on the constructor args to
>> // avoid potential "Most Vexing Parse" issues
>> std::string my_contents(
>> std::istreambuf_iterator<char>(
>> (std::ifstream("reference.cpp").rdbuf())),
>> (std::istreambuf_iterator<char>()));
>> }
>
>
> Can you please tell me in brief how it works. 2nd, you said "Avoid the
> copy", so your program does not copy ?
The example I was referring to had constructed an empty string, and then
copied the file into it.
My example creates the string with the contents of the file, by using
a constructor that takes two iterators.
In actual practice, there won't be much difference, but one-upmanship
sometimes comes into play on this newsgroup! <grin>
> All I can see is its a template. What about error checking whether file
> was opened successfully or not, we are nto even closing the file after we
> finish ? I have Stroustrup 3/e in my hands, checking out what rdbuf()
> does from section 21.6.3, page 644.
It is "template" code. Error checking, etc... is left as an exercise
for the reader.
rdbuf() returns the streambuf underlying the fstream.
[toc] | [prev] | [next] | [standalone]
| From | arnuld <sunrise@invalid.address> |
|---|---|
| Date | 2011-08-09 06:45 +0000 |
| Message-ID | <4e40d7a6$0$310$14726298@news.sunsite.dk> |
| In reply to | #8578 |
> On Mon, 08 Aug 2011 23:12:30 -0700, red floyd wrote:
> My example creates the string with the contents of the file, by using a
> constructor that takes two iterators.
Chapter Strings, Section 20.3.4 I don't see any constructir which takes 2
arguments. If I go to section 16.3.4 then it does have two iterators in a
constructor but that is std::vector not std::string
> It is "template" code. Error checking, etc... is left as an exercise
> for the reader.
you mean this code will be real-life code based on the ideas you have
given me:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream my_file("reference.cpp");
if(!my_file)
{
std::cerr << "Error Opening file" << std::endl;
exit(EXIT_FAILURE);
}
std::string my_contents(std::istreambuf_iterator<char>(my_file.rdbuf()),
(std::istreambuf_iterator<char>()));
std::cout << "String contents are: "<< "\n"
<< my_contents << std::endl;
my_file.close();
return 0;
}
as usual compiled with "gcc -ansi -pedantic -Wall -Wextra" and it
compiles and runs fine.
--
-- arnuld
www.LispMachine.Wordpress.com
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-08-09 09:26 -0700 |
| Message-ID | <j1rn4i$td1$1@dont-email.me> |
| In reply to | #8579 |
On 8/8/2011 11:45 PM, arnuld wrote:
>> On Mon, 08 Aug 2011 23:12:30 -0700, red floyd wrote:
>
>> My example creates the string with the contents of the file, by using a
>> constructor that takes two iterators.
>
> Chapter Strings, Section 20.3.4 I don't see any constructir which takes 2
> arguments. If I go to section 16.3.4 then it does have two iterators in a
> constructor but that is std::vector not std::string
>
ISO/IEC 14882:2003, sections 21.3/6 [lib.basic.string] and
21.3.1/14 [lib.string.cons]
template<class InputIterator>
basic_string(InputIterator begin, InputIterator end,
const Allocator& a = Allocator());
[toc] | [prev] | [next] | [standalone]
| From | arnuld <sunrise@invalid.address> |
|---|---|
| Date | 2011-08-10 10:58 +0000 |
| Message-ID | <4e426460$0$302$14726298@news.sunsite.dk> |
| In reply to | #8593 |
> On Tue, 09 Aug 2011 09:26:58 -0700, red floyd wrote: > ISO/IEC 14882:2003, sections 21.3/6 [lib.basic.string] and > 21.3.1/14 [lib.string.cons] > template<class InputIterator> > basic_string(InputIterator begin, InputIterator end, > const Allocator& a = Allocator()); I have n3242.pdf and in section 21.3 (page 624) I can't find this (may template syntax is too alien for me). 2nd, even if its there, we used 2 arguments unlike 3 mentioned here. I assume it will have some default value. -- -- arnuld www.LispMachine.Wordpress.com
[toc] | [prev] | [next] | [standalone]
| From | "Bo Persson" <bop@gmb.dk> |
|---|---|
| Date | 2011-08-10 16:19 +0200 |
| Message-ID | <9afiaoFlhoU1@mid.individual.net> |
| In reply to | #8615 |
arnuld wrote: >> On Tue, 09 Aug 2011 09:26:58 -0700, red floyd wrote: > >> ISO/IEC 14882:2003, sections 21.3/6 [lib.basic.string] and >> 21.3.1/14 [lib.string.cons] > >> template<class InputIterator> >> basic_string(InputIterator begin, InputIterator end, >> const Allocator& a = Allocator()); > > I have n3242.pdf and in section 21.3 (page 624) I can't find this > (may template syntax is too alien for me). 2nd, even if its there, > we used 2 arguments unlike 3 mentioned here. I assume it will have > some default value. It is a member (constructor). See page 629 and bottom of page 634. Bo Persson
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-08-10 10:06 -0700 |
| Message-ID | <j1udqh$rq2$1@dont-email.me> |
| In reply to | #8615 |
On 8/10/2011 3:58 AM, arnuld wrote: >> On Tue, 09 Aug 2011 09:26:58 -0700, red floyd wrote: > >> ISO/IEC 14882:2003, sections 21.3/6 [lib.basic.string] and >> 21.3.1/14 [lib.string.cons] > >> template<class InputIterator> >> basic_string(InputIterator begin, InputIterator end, >> const Allocator& a = Allocator()); > > I have n3242.pdf and in section 21.3 (page 624) I can't find this (may > template syntax is too alien for me). 2nd, even if its there, we used 2 > arguments unlike 3 mentioned here. I assume it will have some default > value. The section numbering of n3242 (C++11 draft) differs from the official 2003 Standard.
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-08-09 09:28 -0700 |
| Message-ID | <j1rn6n$td1$2@dont-email.me> |
| In reply to | #8579 |
On 8/8/2011 11:45 PM, arnuld wrote:
> you mean this code will be real-life code based on the ideas you have
> given me:
>
> #include<iostream>
> #include<fstream>
> #include<string>
>
>
> int main()
> {
> std::ifstream my_file("reference.cpp");
> if(!my_file)
> {
> std::cerr<< "Error Opening file"<< std::endl;
> exit(EXIT_FAILURE);
> }
>
> std::string my_contents(std::istreambuf_iterator<char>(my_file.rdbuf()),
> (std::istreambuf_iterator<char>()));
>
> std::cout<< "String contents are:"<< "\n"
> << my_contents<< std::endl;
>
> my_file.close();
>
> return 0;
> }
Just an FYI, the my_file.close() is not required, as the ifstream
destructor will close it for you.
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-08-09 09:33 -0700 |
| Message-ID | <j1rnh3$fo$1@dont-email.me> |
| In reply to | #8579 |
On 8/8/2011 11:45 PM, arnuld wrote:
> you mean this code will be real-life code based on the ideas you have
> given me:
>
> #include<iostream>
> #include<fstream>
> #include<string>
>
>
> int main()
> {
> std::ifstream my_file("reference.cpp");
> if(!my_file)
> {
> std::cerr<< "Error Opening file"<< std::endl;
> exit(EXIT_FAILURE);
> }
>
> std::string my_contents(std::istreambuf_iterator<char>(my_file.rdbuf()),
> (std::istreambuf_iterator<char>()));
>
> std::cout<< "String contents are:"<< "\n"
> << my_contents<< std::endl;
>
> my_file.close();
>
> return 0;
> }
>
> as usual compiled with "gcc -ansi -pedantic -Wall -Wextra" and it
> compiles and runs fine.
Technically. you need to #include <cstdlib> to define EXIT_FAILURE.
In actual practice, obviously one of <iostream>, <fstream>, or <string>
is including it.
Also, I believe std::endl is defined in <ostream>. In C++11 <iostream>
covers that, but in C++03, <iostream> does not officially include
<ostream>, though as far as I know, all known C++ compilers do the
nested include.
[toc] | [prev] | [next] | [standalone]
| From | arnuld <sunrise@invalid.address> |
|---|---|
| Date | 2011-08-10 12:13 +0000 |
| Message-ID | <4e4275ed$0$306$14726298@news.sunsite.dk> |
| In reply to | #8596 |
> On Tue, 09 Aug 2011 09:33:41 -0700, red floyd wrote: > Technically. you need to #include <cstdlib> to define EXIT_FAILURE. I wanted to do it C++ way, how C++ defines exit for failure/success. > In actual practice, obviously one of <iostream>, <fstream>, or <string> > is including it. > Also, I believe std::endl is defined in <ostream>. In C++11 <iostream> > covers that, but in C++03, <iostream> does not officially include > <ostream>, though as far as I know, all known C++ compilers do the > nested include. That is strange. I thought both <istream> and <ostream> were children of parent class <iostream> and they will inherit std::endl from <iostream>. -- -- arnuld www.LispMachine.Wordpress.com
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-08-11 08:57 +0100 |
| Message-ID | <pan.2011.08.11.07.57.41.711000@nowhere.com> |
| In reply to | #8618 |
On Wed, 10 Aug 2011 12:13:33 +0000, arnuld wrote: > That is strange. I thought both <istream> and <ostream> were children of > parent class <iostream> and they will inherit std::endl from <iostream>. <istream>, <ostream> and <iostream> are headers, not classes, although classes with those names exist. Also, std::endl() is a function, not a method.
[toc] | [prev] | [next] | [standalone]
| From | "Bo Persson" <bop@gmb.dk> |
|---|---|
| Date | 2011-08-11 12:51 +0200 |
| Message-ID | <9ahqgnFlk2U1@mid.individual.net> |
| In reply to | #8659 |
Nobody wrote: > On Wed, 10 Aug 2011 12:13:33 +0000, arnuld wrote: > >> That is strange. I thought both <istream> and <ostream> were >> children of parent class <iostream> and they will inherit >> std::endl from <iostream>. > > <istream>, <ostream> and <iostream> are headers, not classes, > although classes with those names exist. > > Also, std::endl() is a function, not a method. And even better (or worse?) is that iostream inherits from both istream and ostream, not the other way round. Bo Persson
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-08-12 05:00 +0100 |
| Message-ID | <pan.2011.08.12.04.00.23.833000@nowhere.com> |
| In reply to | #8666 |
On Thu, 11 Aug 2011 12:51:10 +0200, Bo Persson wrote: >>> That is strange. I thought both <istream> and <ostream> were >>> children of parent class <iostream> and they will inherit >>> std::endl from <iostream>. >> >> <istream>, <ostream> and <iostream> are headers, not classes, >> although classes with those names exist. >> >> Also, std::endl() is a function, not a method. > > And even better (or worse?) is that iostream inherits from both > istream and ostream, not the other way round. Right. istream and ostream inherit from ios, the common base class for all streams. iostream is the input-AND-output stream class (i.e. read-write streams, analogous to fopen()'s "plus" modes: r+/w+/a+).
[toc] | [prev] | [next] | [standalone]
| From | Nana J. Osei <mppccf0987@att.net> |
|---|---|
| Date | 2011-08-13 23:18 +0000 |
| Message-ID | <j270nl$k61$1@speranza.aioe.org> |
| In reply to | #8566 |
Gee, thank you very much. This one liner magic works! I owe you one. Do you accept bitcoins? Just a token of appreciation...
[toc] | [prev] | [next] | [standalone]
| From | Sam <sam@email-scan.com> |
|---|---|
| Date | 2011-08-13 20:58 -0500 |
| Message-ID | <cone.1313287126.273902.31590.500@monster.email-scan.com> |
| In reply to | #8802 |
[Multipart message — attachments visible in raw view] — view raw
Nana J. Osei writes: > Gee, thank you very much. This one liner magic works! I owe you one. Do you > accept bitcoins? Just a token of appreciation... If you're addressing me, judging by the References: header, thanks but I'm not into bitcoins.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c++
csiph-web