473,779 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Odd behaviour with istream_iterato r

I'm using gcc 3.3.5. This code:

std::set<std::s tringt(std::ist ream_iterator<s td::string>(std ::cin),
std::istream_it erator<std::str ing>());

gives a strange error message:

error: cannot use `::' in parameter declaration

If I try it this way:

std::istream_it erator<std::str ingis(std::cin) ;
std::istream_it erator<std::str ingeof();
std::set<std::s tringt(is, eof);

it also gives an error:

error: no matching function for call to `std::set<*snip *>::set(*snip*) '

Strangely enough, this:

std::set<std::s tringt((std::is tream_iterator< std::string>(st d::cin)),
std::istream_it erator<std::str ing>());

compiles and works just fine. The only difference is the extra
parentheses around the first parameter. I can't get the second version
above to compile regardless of any amount of parentheses anywhere.

Even more strangely, if I add the extra parentheses around the
second parameter, like this:

std::set<std::s tringt((std::is tream_iterator< std::string>(st d::cin)),
(std::istream_i terator<std::st ring>()));

it once again doesn't compile:

error: syntax error before `)' token

I don't understand this. What's going on?
May 17 '07 #1
2 1812
edd
On 17 May, 17:57, Juha Nieminen <nos...@thanks. invalidwrote:
I'm using gcc 3.3.5. This code:

std::set<std::s tringt(std::ist ream_iterator<s td::string>(std ::cin),
std::istream_it erator<std::str ing>());

gives a strange error message:

error: cannot use `::' in parameter declaration

If I try it this way:

std::istream_it erator<std::str ingis(std::cin) ;
std::istream_it erator<std::str ingeof();
std::set<std::s tringt(is, eof);

it also gives an error:

error: no matching function for call to `std::set<*snip *>::set(*snip*) '
I believe it's a bug in gcc 3.3. It thinks you're declaring a function
called 't'. Similarly for your second error, it thinks a function
called 'is' is being declared.
http://www.gnu.org/software/gcc/bugs.html#known (Parse errors for
"simple" code)

gcc 3.4 and onwards should cope fine.

Here is another possible work around (don't have 3.3 on this machine
to test the theory):

typedef std::istream_it erator<std::str ingiter_t;
iter_t is = iter_t(std::cin );
iter_t eof;
std::set<std::s tringt(is, eof);

Kind regards,

Edd

May 17 '07 #2
On May 17, 6:57 pm, Juha Nieminen <nos...@thanks. invalidwrote:
I'm using gcc 3.3.5. This code:

std::set<std::s tringt(std::ist ream_iterator<s td::string>(std ::cin),
std::istream_it erator<std::str ing>());

gives a strange error message:

error: cannot use `::' in parameter declaration
Compiler tries to look on your line as on a function declaration
(function t, which receives istream_iterato r with improper param name
std::cin (cant use qualified names in function param declaration), and
a pointer to function which receives nothing, returns
istream_iterato r(unnamed second parameter of t). Finally, function t
returns a set).
If I try it this way:

std::istream_it erator<std::str ingis(std::cin) ;
std::istream_it erator<std::str ingeof();
std::set<std::s tringt(is, eof);

here you have another function delcaration - eof (receives nothing,
returns istream_iterato r), thats why you cant toss it to t's
constructor second param.

Remember: function declarations can be local, and they're given
priority when deciding what the line of code means.
>
std::set<std::s tringt((std::is tream_iterator< std::string>(st d::cin)),
std::istream_it erator<std::str ing>());
because you cant use parentheses around a param in a function
declaration, this is correctly interpreted as a set constructor call.

Dont know about the last lines you posted. They compile fine on VS
2005 compiler.

May 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4160
by: Bill Rudolph | last post by:
The member function basic_ios::operator!() returns the bool result of the basic_ios::fail() function which is true if either failbit or badbit is set (This is per p. 616 of TC++PL by B. Stroustrup and p. 34 of Standard C++ IOStreams and Locales by Angelika Langer and Klaus Kreft). The implementation of the input stream iterator in the Langer and Kreft book (see p. 129 to 130) uses the function: void readElem()
3
2159
by: NPC | last post by:
Hi, Is there any way to use an istream_iterator<> in a way which inserts each element at the end of a newline character rather than a space character? Could be it looks for any type of whitespace - not sure about that. In particular, it would be nice to use it in a way which is similar to an ostream_iterator: std::vector<std::string> myVec; /* add stuff to myVec */
9
3184
by: Alex Vinokur | last post by:
------ foo.cpp : BEGIN ------ #include <cassert> #include <vector> #include <string> #include <iostream> #include <iterator> #include <fstream> using namespace std;
2
1461
by: ben | last post by:
Is istream_iterator<> and ostream_iterator<> supposed NOT to be included in <iostream>? The following example compiles in VC 7.1 but not with gcc 3.4.3 #include <iostream> #include <deque> #include <algorithm> int main() { using namespace std;
0
5147
by: Richo11 | last post by:
This is probably a silly question but I am learning sorry... I am trying to read in a series of strings from standard input using the istream_iterator member function, how does istream_iterator<string>eos work. How does it know that you have finished entering data? :confused: any help appreciated. Cheers Richo
2
1649
by: alberto | last post by:
I am learning STL with the book STL Tutorial and Reference guide (1 edition), the following example don't run : int main() { // Initialize array a with 10 integers: int a = {12, 3, 25, 7, 11, 213, 7, 123, 29, -31}; // Find the first element equal to 7 in the array: int* ptr = find(&a, &a, 7);
2
7074
by: Marcus Kwok | last post by:
I am writing a program to read in a file, do some processing, then write it out to a different file. I really like the idiom I use for output: // std::vector<std::string> vec; // std::ofstream out; std::copy(vec.begin(), vec.end(), std::ostream_iterator<std::string>(out, "\n"));
3
3820
by: jmoy.matecon | last post by:
I get an error while compiling the following program: int main() { vector<int> v(istream_iterator<int>(cin), istream_iterator<int>()); copy(v.begin(),v.end(),ostream_iterator<int>(cout,"\n")); } The errors I get are is:
5
2837
by: Pradeep | last post by:
Hi All, I am facing some problem using istream_iterator for reading the contents of a file and copying it in a vector of strings.However the same thing works for a vector of integers. The code that doesn't work is std::vector<std::stringvecStr; std::ifstream fstrRead("Test.txt");
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.