By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,695 Members | 1,284 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,695 IT Pros & Developers. It's quick & easy.

reading a Text-File into Vector of Strings

P: n/a
This is the partial-program i wrote, as usual, i ran into problems
halfway:
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read its
coontents into a vector of strings, storinig each line as separate
element in vector.
*
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
/* using Pointers because 1st argument is an input file-stream and
for 2nd argument i want to take the original vector, not the copied
one.

next line is the source of error, line #22 */
void read_file( ifstream* my_file, std::vector<std::string>* svec )
{
ifstream infile;
infile.open("my_file");

/* Process File
Here
*/
}
int main()
{
std::vector<std::stringsvec;
std::vector<std::string>* psvec;

std::cout << "Enter the full Path to file: "; ifstream my_file;
ifstream* p_my_file;

std::cin >p_my_file;

read_file( p_my_file, psvec );

return 0;
}

-------- OUTPUT --------------
[arnuld@Arch64 c++]$ g++ -ansi -pedantic -Wall -Wextra ex_08-09.cpp
ex_08-09.cpp:22: error: variable or field ‘read_file’ declared void
ex_08-09.cpp:22: error: ‘ifstream’ was not declared in this scope
ex_08-09.cpp:22: error: ‘my_file’ was not declared in this scope
ex_08-09.cpp:22: error: expected primary-expression before ‘*’ token
ex_08-09.cpp:22: error: 'svec' was not declared in this scope
ex_08-09.cpp: In function 'int main()':
ex_08-09.cpp:39: error: 'ifstream' was not declared in this scope
ex_08-09.cpp:39: error: expected `;' before ‘my_file’
ex_08-09.cpp:40: error: 'p_my_file' was not declared in this scope
ex_08-09.cpp:44: error: 'read_file' was not declared in this scope
[arnuld@Arch64 c++]$
Opening the file is the 1st stage of the problem. 2nd stage will include
copying the each line as a library string into the vector. I am facing
problems at very 1st stage.

--
http://lispmachine.wordpress.com

Sep 13 '07 #1
Share this Question
Share on Google+
15 Replies


P: n/a

"arnuld" <ge*********@gmail.comwrote in message
news:pa****************************@gmail.com...
This is the partial-program i wrote, as usual, i ran into problems
halfway:
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read its
coontents into a vector of strings, storinig each line as separate
element in vector.
*
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
/* using Pointers because 1st argument is an input file-stream and
for 2nd argument i want to take the original vector, not the copied
one.

next line is the source of error, line #22 */
void read_file( ifstream* my_file, std::vector<std::string>* svec )
{
ifstream infile;
infile.open("my_file");

/* Process File
Here
*/
}
Your function is a bit strange. If the first arg is an input
file stream, why aren't you using it?
You create a new ifstream and call open with a file name?
Maybe you just want to pass the file name to the function.
Or do you want the stream to stay open after this function
finishes?

Also, you don't need a pointer to your vector. Probably
better to pass it by reference.
>
int main()
{
std::vector<std::stringsvec;
std::vector<std::string>* psvec;

std::cout << "Enter the full Path to file: "; ifstream my_file;
ifstream* p_my_file;
Shouldn't ifstream be in the std namespace?
Sep 13 '07 #2

P: n/a
On 2007-09-13 13:11, arnuld wrote:
This is the partial-program i wrote, as usual, i ran into problems
halfway:
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read its
coontents into a vector of strings, storinig each line as separate
element in vector.
*
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
/* using Pointers because 1st argument is an input file-stream and
for 2nd argument i want to take the original vector, not the copied
one.

next line is the source of error, line #22 */
void read_file( ifstream* my_file, std::vector<std::string>* svec )
void read_file(std::istream& my_file, std::vector<std::string>& vec)

For these kinds of things (passing the actual object and not a copy) a
reference is preferable, unless you need to be able to pass NULL.
{
ifstream infile;
infile.open("my_file");
Looking at the code in main() it looks like the file should already be
open at this point.
>
/* Process File
Here
*/
Look into using std::getline() for reading the contents of the file.
}
int main()
{
std::vector<std::stringsvec;
std::vector<std::string>* psvec;

std::cout << "Enter the full Path to file: "; ifstream my_file;
ifstream* p_my_file;
Don't use a pointer, "ifstream my_file;" will do.
>
std::cin >p_my_file;
One problem with using the >operator here is that it will not allow
for filenames containing spaces (I seem to recall that you can set the
delimiter somehow to change this behaviour). I would use std::getline()
here too. One you have the filename use my_file.open() to open the file
(don't forget to check that it succeeded).
Opening the file is the 1st stage of the problem. 2nd stage will include
copying the each line as a library string into the vector. I am facing
problems at very 1st stage.
You should probably re-read the chapter about filestreams, opening them
are quite easy, you just use the filename as argument to the constructor
or use the open() function:

std::ifstream file("myfile.txt");

or

std::ifstream file;
file.open("myfile.txt");

--
Erik Wikström
Sep 13 '07 #3

P: n/a
In article <pa****************************@gmail.com>,
ge*********@gmail.com says...

[ ... ]
/* using Pointers because 1st argument is an input file-stream and
for 2nd argument i want to take the original vector, not the copied
one.
You probably don't want to use pointers here -- you almost certainly
want to use references instead. For reference (no pun intended) you
should virtually _always_ plan on passing any stream by reference.
next line is the source of error, line #22 */
void read_file( ifstream* my_file, std::vector<std::string>* svec )
That needs to be 'std::ifstream'.
ex_08-09.cpp:22: error: variable or field ?read_file? declared void
Without the 'std::' on the beginning, the compiler doesn't recognize
that 'ifstream' is supposed to be a type. It's trying to read it as a
value, so it thinks you have something like:

int x(1);

but it's telling you that you can't define a variable of type 'void'.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Sep 13 '07 #4

P: n/a
"arnuld" <ge*********@gmail.comwrote in message
news:pa****************************@gmail.com...
This is the partial-program i wrote, as usual, i ran into problems
halfway:
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read its
coontents into a vector of strings, storinig each line as separate
element in vector.
*
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
/* using Pointers because 1st argument is an input file-stream and
for 2nd argument i want to take the original vector, not the copied
one.

next line is the source of error, line #22 */
void read_file( ifstream* my_file, std::vector<std::string>* svec )
{
ifstream infile;
infile.open("my_file");

/* Process File
Here
*/
}
int main()
{
std::vector<std::stringsvec;
std::vector<std::string>* psvec;

std::cout << "Enter the full Path to file: "; ifstream my_file;
ifstream* p_my_file;

std::cin >p_my_file;

read_file( p_my_file, psvec );

return 0;
}

-------- OUTPUT --------------
[arnuld@Arch64 c++]$ g++ -ansi -pedantic -Wall -Wextra ex_08-09.cpp
ex_08-09.cpp:22: error: variable or field 'read_file' declared void
ex_08-09.cpp:22: error: 'ifstream' was not declared in this scope
ex_08-09.cpp:22: error: 'my_file' was not declared in this scope
ex_08-09.cpp:22: error: expected primary-expression before '*' token
ex_08-09.cpp:22: error: 'svec' was not declared in this scope
ex_08-09.cpp: In function 'int main()':
ex_08-09.cpp:39: error: 'ifstream' was not declared in this scope
ex_08-09.cpp:39: error: expected `;' before 'my_file'
ex_08-09.cpp:40: error: 'p_my_file' was not declared in this scope
ex_08-09.cpp:44: error: 'read_file' was not declared in this scope
[arnuld@Arch64 c++]$
Opening the file is the 1st stage of the problem. 2nd stage will include
copying the each line as a library string into the vector. I am facing
problems at very 1st stage.
Output of the following program on my system is:
Enter the full Path to file: c:\alcsetup.log
[ResponseResult]
ResultCode=0

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

void read_file( std::ifstream& my_file, std::vector<std::string>& svec )
{
std::string Line;
while ( std::getline( my_file, Line ) )
svec.push_back( Line );
}

int main()
{
std::vector<std::stringsvec;
std::cout << "Enter the full Path to file: ";
std::string FileName;
std::cin >FileName;
std::ifstream my_file( FileName.c_str() );
read_file( my_file, svec );

std::copy( svec.begin(), svec.end(),
std::ostream_iterator<std::string>(std::cout, "\n") );

return 0;
}
Sep 13 '07 #5

P: n/a
On Sep 13, 4:49 pm, Erik Wikstrm <Erik-wikst...@telia.comwrote:
>arnuld wrote:
void read_file(std::istream& my_file, std::vector<std::string>& vec)

For these kinds of things (passing the actual object and not a copy) a
reference is preferable, unless you need to be able to pass NULL.
ok

{
ifstream infile;
infile.open("my_file");
Looking at the code in main() it looks like the file should already be
open at this point.
:-\

/* Process File
Here
*/

Look into using std::getline() for reading the contents of the file.
got it.

std::cout << "Enter the full Path to file: "; ifstream my_file;
ifstream* p_my_file;

Don't use a pointer, "ifstream my_file;" will do.
you mean streams magically use references (stream name will be
implicitly converted to a reference ) ?

std::cin >p_my_file;

One problem with using the >operator here is that it will not allow
for filenames containing spaces (I seem to recall that you can set the
delimiter somehow to change this behaviour). I would use std::getline()
here too. One you have the filename use my_file.open() to open the file
(don't forget to check that it succeeded).
ok, done

You should probably re-read the chapter about filestreams, opening them
are quite easy, you just use the filename as argument to the constructor
or use the open() function:

std::ifstream file("myfile.txt");

or

std::ifstream file;
file.open("myfile.txt");
you want to say that fstream is like a library String ?

To manipulate the string 1st you have to create a String using:
std::string a_string;

looks like I have to treat an I/O Stream like a library String. I
thought I/O streams exist automatically, as this is the place where I
type program all the time, using Emacs.

Sep 13 '07 #6

P: n/a
On Sep 13, 6:22 pm, Jerry Coffin <jcof...@taeus.comwrote:
You probably don't want to use pointers here -- you almost certainly
want to use references instead. For reference (no pun intended) you
should virtually _always_ plan on passing any stream by reference.
ex_08-09.cpp:22: error: variable or field ?read_file? declared void

Without the 'std::' on the beginning, the compiler doesn't recognize
that 'ifstream' is supposed to be a type. It's trying to read it as a
value, so it thinks you have something like:

int x(1);

but it's telling you that you can't define a variable of type 'void'.
thanks Jerry, I learned 2 very-important things today :)

Sep 13 '07 #7

P: n/a
On 2007-09-13 18:58, arnuld wrote:
>On Sep 13, 4:49 pm, Erik Wikstrm <Erik-wikst...@telia.comwrote:
>>arnuld wrote:
> void read_file(std::istream& my_file, std::vector<std::string>& vec)

For these kinds of things (passing the actual object and not a copy) a
reference is preferable, unless you need to be able to pass NULL.

ok

{
ifstream infile;
infile.open("my_file");
>Looking at the code in main() it looks like the file should already be
open at this point.

:-\

/* Process File
Here
*/

Look into using std::getline() for reading the contents of the file.

got it.

std::cout << "Enter the full Path to file: "; ifstream my_file;
ifstream* p_my_file;

Don't use a pointer, "ifstream my_file;" will do.

you mean streams magically use references (stream name will be
implicitly converted to a reference ) ?
Not sure what you mean here. The reason you don't need a pointer is that
the lifetime of the istream is equal to the function in which is
declared (main()) so there's really no need to have it on the heap.
Allocating on the heap is usually only needed if the variable have a
lifetime incompatible with the lifetime of the scope in which it is
declared. This way you also don't have to worry about deleting it when
you are done with it.
std::cin >p_my_file;

One problem with using the >operator here is that it will not allow
for filenames containing spaces (I seem to recall that you can set the
delimiter somehow to change this behaviour). I would use std::getline()
here too. One you have the filename use my_file.open() to open the file
(don't forget to check that it succeeded).

ok, done

>You should probably re-read the chapter about filestreams, opening them
are quite easy, you just use the filename as argument to the constructor
or use the open() function:

std::ifstream file("myfile.txt");

or

std::ifstream file;
file.open("myfile.txt");

you want to say that fstream is like a library String ?

To manipulate the string 1st you have to create a String using:
std::string a_string;

looks like I have to treat an I/O Stream like a library String. I
thought I/O streams exist automatically, as this is the place where I
type program all the time, using Emacs.
ifstream is just another class in the library and have to be created
just like any other object. The only streams that do not have to be
created before use are std::cin, std::cout, std::cerr, and std::clog.

--
Erik Wikstrm
Sep 13 '07 #8

P: n/a

arnuld <ge*********@gmail.comwrote in message...
This is the partial-program i wrote, as usual, i ran into problems
halfway:

/* C++ Primer - 4/e * Exercise 8.9 * STATEMENT:
* write a function to open a file for input and then read its
coontents into a vector of strings, storinig each line as separate
element in vector.
*/

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

/* using Pointers because 1st argument is an input file-stream and
for 2nd argument i want to take the original vector, not the copied
one. next line is the source of error, line #22 */
void read_file( ifstream* my_file, std::vector<std::string>* svec ){
ifstream infile;
infile.open("my_file");
/* Process File Here */
}
void read_file( std::string const &my_file, std::vector<std::string>
&svec ){
std::ifstream infile( my_file.c_str() );
if( not infile.is_open() ){ /* error */ }
/* Process File Here */
}
int main(){
std::vector<std::stringsvec;
// std::vector<std::string>* psvec;
>
std::cout << "Enter the full Path to file: "; ifstream my_file;
// ifstream* p_my_file;
// std::cin >p_my_file;

std::string p_my_file;
std::getline( std::cin, p_my_file );

// read_file( p_my_file, psvec );
read_file( p_my_file, svec );
return 0;
}
If you really did want to do what you were thinking, don't limit your
function.

void read_file( std::istream &in, std::vector<std::string&svec ){
// note: that is 'istream', not 'ifstream'.
for( std::string line; std::getline( in, line ); /*m_t*/ ){
svec.push_back( line );
} // for(line)
return;
} // read_file(istream&,vector<string>&)

int main(){
std::vector<std::stringsvec;
std::ifstream infile( "MyFile.txt" );
std::istringstream instring( "This will \n simulate \n" ); // <sstream>

read_file( infile, svec );
read_file( instring, svec );
std::cout<<"Type in some lines"<<std::endl;

/* I'll leave it to you to figure a way to invoke/terminate
input on this one <G>*/
/* hint: ctrl-Z, ctrl-C, [return], as-is, ??? */
read_file( std::cin, svec );

std::copy( svec.begin(), svec.end(),
std::ostream_iterator<std::string>( std::cout, "\n" ) );

return 0;
} // main()

Don't complicate your programming with pointers, unless you are *forced* to.
:-}

--
Bob R
POVrookie
Sep 13 '07 #9

P: n/a
On Sep 13, 11:19 pm, Juha Nieminen <nos...@thanks.invalidwrote:
I feel from your code that you lack basic understanding of C++ types,
pointers, and how they work and are used.

I wonder if you even understand what "ifstream" is and what
"ifstream*" means.

In that function you create a new ifstream and then open it,
suspiciously with the same name as your first function parameter, ie.
"my_file". This makes me suspect that you think that you are opening
that "file" represented by the first function parameter, called
"my_file", by giving the name of that variable, as a string none the
less, to a second ifstream.

The variable named my_file and the string "my_file" have *nothing*
to do with each other. They have absolutely no relation. One is a
variable (in this case of type "pointer-to-ifstream") and the other is
a string literal. Just because the string literal has the same
characters as the name of that variable don't make them related in any way.

Just the fact that you seem to try to be opening an ifstream with
another ifstream seems to show that you don't really understand what the
ifstream class is.
thanks for a lengthy explanation , finally i got it :)

For example, let's assume we have somewhere a function like this:

void foo(std::vector<std::string>& aVector) { ... }

This takes a vector as reference. In other words, a copy of the vector
is *not* given to this function when it's called, but instead just a
reference to the original vector. (You can think of references as
limited pointers.)

Somewhere else you could write this:

std::vector<std::stringmyVector;
foo(myVector);

The first line creates an vector, and the second line calls the foo()
function giving that vector as parameter. But as already seen, the
function doesn't actually take a copy of the vector, but a reference to
it, and thus any modification the function makes to that vector will be
done to the 'myVector' vector.

You could, of course, pass a pointer to your original vector too
(although a reference is usually recommended). In that case you make the
function to take a pointer:

void foo(std::vector<std::string>* aVector) { ... }

and then you can call it like this:

std::vector<std::stringmyVector;
foo(&myVector);

The & operator means "create a pointer pointing to this variable".
Thus the foo() function is given a pointer to 'myVector', and if foo()
modifies the vector behind the pointer, 'myVector' will be modified.

In neither case you need to explicitly create a pointer variable,
like you did. (And even if you created one, you would have to,
naturally, make it point somewhere and not leave it uninitialized like
you did.)

I understood how to use pointer sand references.

std::vector<std::stringlines;
std::string line;

while(inputFileStream.good())
{
std::getline(inputFileStream, line);
lines.push_back(line);

}

That's it. It doesn't need to be more complicated than that.
exercise needs that "reading part" to be in a separate function and
that is what i tried to did again:

/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read its
* coontents into a vector of strings, storinig each line as separate
* element in vector.
*
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
void read_file( std::ifstream& my_file, std::vector<std::string>&
svec )
{
std::string a_line;
while( std::getline( my_file, a_line ))
{
svec.push_back( a_line );
}

}
int main()
{
std::vector<std::stringsvec;
/* std::vector<std::string>& ref_svec = svec; */

std::cout << "Enter the full Path to file: ";
std::string text_file;
std::cin >text_file;

/* std::ifstream infile_stream(text_file.c_str()); */

/* line# 40, this if condition is the source of error */
if ( std::ifstream infile_stream(text_file.c_str()) )
{
read_file( infile_stream, svec );
}
/* check the vector if it contains anything at all
std::copy( svec.begin(), svec.end(),
std::ostream_iterator<std::string>(std::cout, "\n")
);
*/

return 0;
}
----------- OUTPUT -------------------
~/programming/c++ $ g++ -ansi -pedantic -Wall -Wextra ex_08-09.cpp
ex_08-09.cpp: In function 'int main()':
ex_08-09.cpp:40: error: expected primary-expression before
'infile_stream'
ex_08-09.cpp:40: error: expected `)' before 'infile_stream'
ex_08-09.cpp:42: error: 'infile_stream' was not declared in this scope
~/programming/c++ $

Sep 14 '07 #10

P: n/a
On Sep 13, 8:35 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
Output of the following program on my system is:
Enter the full Path to file: c:\alcsetup.log
[ResponseResult]
ResultCode=0

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

void read_file( std::ifstream& my_file, std::vector<std::string>& svec )
{
std::string Line;
while ( std::getline( my_file, Line ) )
svec.push_back( Line );

}

int main()
{
std::vector<std::stringsvec;
std::cout << "Enter the full Path to file: ";
std::string FileName;
std::cin >FileName;
std::ifstream my_file( FileName.c_str() );
read_file( my_file, svec );

std::copy( svec.begin(), svec.end(),
std::ostream_iterator<std::string>(std::cout, "\n") );

return 0;

}
Jim, this program,as it is, never compiles on my system: gcc 4.2.1 on
Arch x86_64 . i get this error: 'ostream_iterator' is not a member
of 'std'

I need to add #include <iteratorto make this program work.
Sep 14 '07 #11

P: n/a
On Fri, 14 Sep 2007 07:09:02 +0000, arnuld wrote:
.... [SNIPPED].........
----------- OUTPUT -------------------
~/programming/c++ $ g++ -ansi -pedantic -Wall -Wextra ex_08-09.cpp
ex_08-09.cpp: In function 'int main()':
ex_08-09.cpp:40: error: expected primary-expression before
'infile_stream'
ex_08-09.cpp:40: error: expected `)' before 'infile_stream'
ex_08-09.cpp:42: error: 'infile_stream' was not declared in this scope
~/programming/c++ $
OK, i got this program to work and it does what exactly the exercise wants
and I only did this change:
std::ifstream infile_stream( text_file.c_str() );
/* 1st check if file was even opened or not */
if( infile_stream.good() )
{
read_file( infile_stream, svec );
}
thanks Juha (for that ".good()", the child-class of <iostream:)
--
http://lispmachine.wordpress.com

Sep 14 '07 #12

P: n/a
arnuld wrote:
~/programming/c++ $ g++ -ansi -pedantic -Wall -Wextra ex_08-09.cpp
ex_08-09.cpp: In function 'int main()':
ex_08-09.cpp:40: error: expected primary-expression before
'infile_stream'
ex_08-09.cpp:40: error: expected `)' before 'infile_stream'
ex_08-09.cpp:42: error: 'infile_stream' was not declared in this scope
~/programming/c++ $
Even though the error messages are cryptic, try to examine the
line where the first error happens (the line number is given in the
error message). That's usually a very good hint of what's wrong.

That's the most basic method of removing errors: Examine the
*first* error message and try to resolve why it's happening, and
fix it (usually it's quite clear why it's happening). Don't worry
about the rest of the error messages. Recompile. If there are still
errors, reiterate the process.
Sep 14 '07 #13

P: n/a
On 2007-09-14 09:51, arnuld wrote:
>On Fri, 14 Sep 2007 07:09:02 +0000, arnuld wrote:
>.... [SNIPPED].........
>----------- OUTPUT -------------------
~/programming/c++ $ g++ -ansi -pedantic -Wall -Wextra ex_08-09.cpp
ex_08-09.cpp: In function 'int main()':
ex_08-09.cpp:40: error: expected primary-expression before
'infile_stream'
ex_08-09.cpp:40: error: expected `)' before 'infile_stream'
ex_08-09.cpp:42: error: 'infile_stream' was not declared in this scope
~/programming/c++ $

OK, i got this program to work and it does what exactly the exercise wants
and I only did this change:
std::ifstream infile_stream( text_file.c_str() );
/* 1st check if file was even opened or not */
if( infile_stream.good() )
{
read_file( infile_stream, svec );
}
thanks Juha (for that ".good()", the child-class of <iostream:)
good() is a member function of the stream, not a class.

PS. Your program does not work correctly with a file named "my file.txt"

--
Erik Wikström
Sep 14 '07 #14

P: n/a
On Sep 14, 2:06 pm, Erik Wikstrm <Erik-wikst...@telia.comwrote:
good() is a member function of the stream, not a class.
:-\

PS. Your program does not work correctly with a file named "my file.txt"
fixed

std::string text_file;
//std::cin >text_file;
std::getline( std::cin, text_file );

just changed the input method :)

Sep 14 '07 #15

P: n/a
"arnuld" <ge*********@gmail.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
>On Sep 13, 8:35 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
>Output of the following program on my system is:
Enter the full Path to file: c:\alcsetup.log
[ResponseResult]
ResultCode=0

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

void read_file( std::ifstream& my_file, std::vector<std::string>& svec )
{
std::string Line;
while ( std::getline( my_file, Line ) )
svec.push_back( Line );

}

int main()
{
std::vector<std::stringsvec;
std::cout << "Enter the full Path to file: ";
std::string FileName;
std::cin >FileName;
std::ifstream my_file( FileName.c_str() );
read_file( my_file, svec );

std::copy( svec.begin(), svec.end(),
std::ostream_iterator<std::string>(std::cout, "\n") );

return 0;

}

Jim, this program,as it is, never compiles on my system: gcc 4.2.1 on
Arch x86_64 . i get this error: 'ostream_iterator' is not a member
of 'std'

I need to add #include <iteratorto make this program work.
Hmm.. all I can say is most likely one of my includes must include
<iteratorbecause it compiled on my compiler. But, yes, it can be a bit of
a pain to show code that won't compile on all implementations. I'll try to
remember to #include <iteratorin the future.
Sep 14 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.