error using ifstream

I thought I knew how to do this, but evidently not. Here's the offending code:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <fstream>
using namespace std;
.
.
.
	ifstream s;
	string fileName;

	fileName = "filename.txt";
	s.open(fileName.c_str());

	getVector (s, NBR_COEFFS_DEMOD_NYQ, count);


I'm getting an error that
/usr/include/c++/4.2.1/bits/ios_base.h:779: error: 'std::ios_base::ios_base(const std::ios_base&)' is private
The error is on the getVector line.

To me, this example looks just like the one in the reference page. What am I doing wrong here?
std::iostream objects can't be copied. Change the type of the first parameter to getVector() to 'std::istream &'.
istream or ifstream? I left it as ifstream, and now I get this:

Undefined symbols:
"getVector(std::basic_istream<char, std::char_traits<char> >&, long, __gnu_cxx::__normal_iterator<FlipFlopReg32*, std::vector<FlipFlopReg32, std::allocator<FlipFlopReg32> > >)", referenced from:


It tells me later that it's coming from the code above.
The linker cannot find the compiled object code containing the function getVector
It looks like you changed only the declaration and not the definition.
Ahh...my definition of getVector was a long, but I was calling it as though it were a void. Fussy, fussy C++.

Thanks, guys.
I realize that I've marked this as solved, but...I'd like to ask a follow-on question:

If I wanted to make my getVector() function a little more flexible, so I can specify whether to read the file in hex or decimal notation, what's the best way to do this? Here's what it currently looks like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int	getVector(ifstream& s,
			  long nbrCells,
			  vector<FlipFlopReg32>::iterator iter)
{
	int		rc = 0;
	int32_t	temp;
	for (int i = 0; i < nbrCells; i++)
	{
		s >> hex >> temp;
		*iter++ = temp;
	}
	if (s.fail())
		rc = 1;
	return rc;
}


Can I change that "hex" to a variable somehow, and have that variable passed through by a calling routine?

EDIT: this question is different enough from the original that I'll ask it in another thread. Thanks.
Last edited on
Topic archived. No new replies allowed.