473,769 Members | 3,872 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 1811
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
3183
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
5138
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
7073
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
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
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
9984
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
8863
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...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.