473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

file i/o with stream_iterators - error

Hi,
could you please tell me why the following program gives a compilation
error ? what does this error mean ?
note also that when i derefernce the iterator , the contents are
displayed.

int main()
{
ifstream ifs("file") ;
istream_iterator<string> i_it(ifs) ;
copy(i_it.begin(), i_it.end(),ostream_iterator<string>(cout,"\n")) ;
}
___________________________
Complier error -
(SunOS 5.8 , g++ )
13 : no matching function for call to `istream_iterator<basic_stri
ng<char,string_char_traits<char>,__default_alloc_t emplate<false,0>
,int>::begin ()' 13: no matching function for call to `istream_iterator<basic_stri
ng<char,string_char_traits<char>,__default_alloc_t emplate<false,0>,int>::end ()'

______________________
regards,
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Jul 19 '05 #1
5 1665
Aman wrote in news:450f74dbb85ab55d80d1df17aa0dd289.26421
@mygate.mailgate.org:
Hi,
could you please tell me why the following program gives a compilation
error ? what does this error mean ?
note also that when i derefernce the iterator , the contents are
displayed.

int main()
{
ifstream ifs("file") ;
istream_iterator<string> i_it(ifs) ;
copy(i_it.begin(), i_it.end(),ostream_iterator<string>(cout,"\n")) ;

copy(
i_it,
istream_iterator<string>(),
ostream_iterator<string>(cout,"\n")
);

}
___________________________
Complier error -
(SunOS 5.8 , g++ )
13 : no matching function for call to `istream_iterator<basic_stri
ng<char,string_char_traits<char>,__default_alloc_t emplate<false,0>
,int>::begin ()'

Your trying to use an input iterator like its a container.

As I've done above use a default constructed istream_iterator<string>
as the end iterator.

13: no matching function for call to `istream_iterator<basic_stri
ng<char,string_char_traits<char>,__default_alloc_t emplate<false,0>
,int>::end ()'

______________________

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #2

copy(
i_it,
istream_iterator<string>(),
ostream_iterator<string>(cout,"\n")
);

That's neat .

HTH

Rob.


Thanks Rob !,

regards,
Aman.


--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Jul 19 '05 #3
Rob Williscroft wrote:

[snip]
copy(
i_it,
istream_iterator<string>(),
ostream_iterator<string>(cout,"\n")
);


Can you please explain why this works. I was under the impression that
the 'end' iterator had to be related to the 'begin' iterator in some
way. Thanks,

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
Jul 19 '05 #4
David Rubin wrote:
Rob Williscroft wrote:

[snip]
copy(
i_it,
istream_iterator<string>(),
ostream_iterator<string>(cout,"\n")
);

Can you please explain why this works. I was under the impression that
the 'end' iterator had to be related to the 'begin' iterator in some
way. Thanks,


You snipped the declaration and definition of i_it, so here it is again:
------------------------------------------
ifstream ifs("file") ;
istream_iterator<string> i_it(ifs) ;
------------------------------------------

The 'end' iterator of any istream_iterator<T> is istream_iterator<T>().
I'll agree that the syntax is not intuitive, as it looks like a call
to the default constructor, but that's something we all have to live with.

As another example, here is a program that fills a container from the
standard input:

-------------------------------------
#include <vector>
#include <string>
#include <iterator>
#include <iostream>

using namespace std;

int
main()
{
vector<string> v;

copy(istream_iterator<string>(cin),
istream_iterator<string>(), // 'end' iterator
back_inserter(v));

cout << "Recieved " << v.size() << " strings as input.\n";

return 0;
}
-------------------------------------

--
Reverse domain name to reply.

Jul 19 '05 #5
David Rubin escribió:
copy(
i_it,
istream_iterator<string>(),
ostream_iterator<string>(cout,"\n")
);


Can you please explain why this works. I was under the impression that
the 'end' iterator had to be related to the 'begin' iterator in some
way. Thanks,


Because the operator = that compares two istream_iterator is written
that way, it gives a value of true when comparing one that has reached
his end to one default constructed. It's a simple solution that does not
need to define additional functions.

Regards.
Jul 19 '05 #6

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

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
1
by: jase_dukerider | last post by:
Hi I have an assignment to hand in shortly for which I am after some guidance. The task is to read a WAV file, request a fade in /out time for the track from the user and the do the fade by...
7
by: Mark | last post by:
Hello, I have researched and tried every thing I have found on the web, in groups and MS KB articles. Here is what I have. I have a Windows 2000 Domain Controller all service packs and...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
4
by: pank7 | last post by:
hi everyone, I have a program here to test the file IO(actually output) with buffer turned on and off. What I want to see is that there will be obvious differece in time. Here I have an input...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.