473,756 Members | 6,250 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 2044
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
2823
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
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
3182
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;
1
2568
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
7071
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
3819
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
3111
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
1330
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
9303
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
9117
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
9894
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9679
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...
0
8542
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
7078
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
4955
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...
1
3651
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
3
2508
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.