Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linker can't find "read" and "write" functions in istream an

Status
Not open for further replies.

thebaybear

Programmer
May 25, 2001
3
US
I'm trying to overload these functions (&quot;read&quot; and &quot;write&quot;) to do random binary file I/O -- have a good text that shows me exactly how to do it. Everything compiles -- but the linker gives both the old &quot;error LNK2001: unresolved external.&quot; My compiler is Microsoft Visual C++ 6.0, Standard Edition, and I installed everything that came with it. I've included header files <fstream> , <iostream>, <istream>, and <ostream>. Is there a missing .lib or .dll file? Is there a possible conflict with an earlier version of Microsoft ordinary C (6.00) or an old Borland C++ on the system, so that the linker is searching the wrong file? PLEASE HELP -- I need random binary file I/O for a project I'm working on.
 
I've had the &quot;using namespace std;&quot; directive in the whole time. Thanks, but it's something else.
 
Dude, cut and paste this code example of read-write in C++. This will rule out whether it is your installation or a program bug.

// read a file into memory
#include <iostream>
#include <fstream>
using namespace std;

int main () {
int length;
char * buffer;

ifstream is;
is.open (&quot;test.txt&quot;, ios::binary ); //you supply file

// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);

// allocate memory:
buffer = new char [length];

// read data as a block:
is.read (buffer,length);

is.close();

cout.write (buffer,length);

return 0;
}

 
Thanks, jtm111 -- your code links okay, so it's not my installation. It's the code -- program 19.5 of &quot;Ivor Horton's Begginning C++,The Complete Language&quot; as downloaded from his publisher at -- still trying to figure out why his attempt to overload &quot;read&quot; and &quot;write&quot; causes a link error, but you sure have me started in the right direction. Profound thanks!
 
Thanks to JTM and everybody else who helped with this. PROBLEM SOLVED! As it turns out, it was a typo error, moving an ampersand from the prototype of the overloaded &quot;read&quot; to the prototype of the overloaded &quot;write,&quot; so that neither matched the actual function overload. It does, however, point out a hazard of C++ and a typical weakness of Microsoft error messages: everything compiled, but the linker was looking for non-existent third versions of &quot;read&quot; and &quot;write&quot; to match the erroneous prototype declarations. Would have helped a lot if Microsoft had the foresight to make the error message &quot;Unresolved External: THIRD declaration of write,&quot; or if it echoed the prototype it was looking for. But no, you have to guess how many overloads the linker is looking for when it can't resolve an external, with only the function name and a bunch of gobbledygook that only makes sense to the people who write linkers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top