L*******s 发帖数: 63 | 1 Might be a stupid question...:
Why
std::string sContent((std::istreambuf_iterator(fi)),
std::istreambuf_iterator());
doesn't work, but
std::string sContent(std::istreambuf_iterator(fi),
std::istreambuf_iterator());
works? Thanks a lot! | t****t 发帖数: 6806 | 2 http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.2
【在 L*******s 的大作中提到】 : Might be a stupid question...: : Why : std::string sContent((std::istreambuf_iterator(fi)), : std::istreambuf_iterator()); : doesn't work, but : std::string sContent(std::istreambuf_iterator(fi), : std::istreambuf_iterator()); : works? Thanks a lot!
| P********e 发帖数: 2610 | 3 what do you mean by first doesn't work?
It is a valid statement.
【在 L*******s 的大作中提到】 : Might be a stupid question...: : Why : std::string sContent((std::istreambuf_iterator(fi)), : std::istreambuf_iterator()); : doesn't work, but : std::string sContent(std::istreambuf_iterator(fi), : std::istreambuf_iterator()); : works? Thanks a lot!
| P********e 发帖数: 2610 | | t****t 发帖数: 6806 | 5 for c++ opinion, just keep it to yourself.
【在 P********e 的大作中提到】 : man, they are different.
| t****t 发帖数: 6806 | 6 ok, let me explain a bit. this is easy to get wrong.
i believe your original intention is to declare a string object sContent,
and initialize it with 2 iterators. that is fine. however, just as
int b;
declare an integer object b, while
int b();
declares a function called b, returning int, taking no parameters.
your 2nd statement (i will omit decorations)
string a(istreambuf_iterator(fi), istreambuf_iterator());
declares a function called a, returning string, taking 2 parameters: first
should be istreambuf_iterator, second should be a function pointer
returning istreambuf_iterator and taking no parameter.
1st statement with the extra () will prevent compiler from recognizing it as
function declaration, so it does what you want. if it doesn't work, there
must be something else wrong.
【在 L*******s 的大作中提到】 : Might be a stupid question...: : Why : std::string sContent((std::istreambuf_iterator(fi)), : std::istreambuf_iterator()); : doesn't work, but : std::string sContent(std::istreambuf_iterator(fi), : std::istreambuf_iterator()); : works? Thanks a lot!
| L*******s 发帖数: 63 | 7 Sorry, I meant the 1st one works, but the 2nd one doesn't.
(it did turn out to a stupid question...)
【在 P********e 的大作中提到】 : what do you mean by first doesn't work? : It is a valid statement.
| L*******s 发帖数: 63 | 8 Thanks a lot!
sContent,
first
【在 t****t 的大作中提到】 : ok, let me explain a bit. this is easy to get wrong. : i believe your original intention is to declare a string object sContent, : and initialize it with 2 iterators. that is fine. however, just as : int b; : declare an integer object b, while : int b(); : declares a function called b, returning int, taking no parameters. : your 2nd statement (i will omit decorations) : string a(istreambuf_iterator(fi), istreambuf_iterator()); : declares a function called a, returning string, taking 2 parameters: first
| c**b 发帖数: 2999 | 9 第一个参数太长,有时候compiler对太长的一串东西会有误解,所以全部括起来,安全起
见.
【在 L*******s 的大作中提到】 : Might be a stupid question...: : Why : std::string sContent((std::istreambuf_iterator(fi)), : std::istreambuf_iterator()); : doesn't work, but : std::string sContent(std::istreambuf_iterator(fi), : std::istreambuf_iterator()); : works? Thanks a lot!
| t****t 发帖数: 6806 | 10 靠, 没听说过这种理由.
【在 c**b 的大作中提到】 : 第一个参数太长,有时候compiler对太长的一串东西会有误解,所以全部括起来,安全起 : 见.
| t****t 发帖数: 6806 | 11 by the way, this is explained exactly in . Item 6, to be
precise. I lost the book when moving, pity.
i believe you can find E-version of the book online.
【在 L*******s 的大作中提到】 : Thanks a lot! : : sContent, : first
|
|