473,715 Members | 5,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

istream_iterato r and ostream_iterato r problem

Hello all... I get an error message for the following program by the
compiler:

#include <iostream>
#include <string>

using namespace std;

ostream_iterato r<string> oo(cout);

int main()
{
*oo = "Hello ";
++oo;
*oo = "world!\n";

return 0;
}

the error says: "ostream_iterat or is used as a type, but is not
defined as a type."... What can I do to fix that?? I get the same
error with istream_iterato r...

cmad
Jul 22 '05 #1
2 2038
Chris Mantoulidis wrote in news:a8587dd9.0 312132333.52617 1b8
@posting.google .com:
Hello all... I get an error message for the following program by the
compiler:

#include <iostream>
#include <string>

#include <iterator>
using namespace std;

ostream_iterato r<string> oo(cout);

int main()
{
*oo = "Hello ";
++oo;
*oo = "world!\n";

return 0;
}

the error says: "ostream_iterat or is used as a type, but is not
defined as a type."... What can I do to fix that?? I get the same
error with istream_iterato r...


std::ostream_it erator is declared in <iterator>.

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2
>>>>> ">>" == Chris Mantoulidis <cm****@yahoo.c om> writes:
Hello all... I get an error message for the following program by the
compiler: #include <iostream>
#include <string>

using namespace std;

ostream_iterato r<string> oo(cout);
int main()
{
*oo = "Hello ";
++oo;
*oo = "world!\n";
return 0;
} the error says: "ostream_iterat or is used as a type, but is not
defined as a type."... What can I do to fix that?? I get the same
error with istream_iterato r... cmad


Chris,

You need to include <iterator>!

ostream_iterato r exists as a unique template class as compared to the
iterators of STL containers which use traits to create their own nested
iterator classes, hence the scope resolution operator "::" when these are
instantiated, eg.

vector<int> my_vec(10);
// ...
vector<int>::it erator my_vec_itor = my_vec.begin();

.... you could even use a little more of the STL:

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

using namespace std;

int main()
{
vector<string> oo_vec;
oo_vec.push_bac k("Hello ");
oo_vec.push_bac k("world!\n") ;
copy(oo_vec.beg in(), oo_vec.end(), ostream_iterato r<string>(cout) );

return 0;
}

J.
--
Jul 22 '05 #3

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

Similar topics

10
2813
by: Alex Vinokur | last post by:
ofstream outfile ("out"); ifstream infile ("in"); istream_iterator<char> iter(infile), eos; Is it possible to copy 'infile' to 'outfile' using 'iter' and 'eos'? -- Alex Vinokur mailto:alexvn@connect.to http://mathforum.org/library/view/10978.html
3
2156
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
3177
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
1456
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;
1
2563
by: Dave | last post by:
#include <iostream> #include <list> #include <string> using namespace std; int main() { list<string> the_list( (istream_iterator<string>(cin)),
2
7065
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
3817
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:
8
3106
by: dragoncoder | last post by:
Hi, I am just a newbie in STL and trying to learn istream_iterator. My problem is I want a program which will take a comma separated string from the command line, tokenize it and copies into a vector. Then I am printing the vector. Here is the code I tried. #include <iostream> #include <sstream> #include <vector>
2
1325
by: tong | last post by:
i have tried a program that it should show all words i typed, but it can't e.g. 1 2 3 1 <-- 2 <-- it always miss the last one then i continue to type 4 3 <-- it shows now !!
0
8821
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...
1
9103
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
9047
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...
1
6646
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
4477
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
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
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
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2118
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.