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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input from a file problems

Status
Not open for further replies.

Tatchster

Programmer
Oct 13, 2002
3
0
0
AU
i am trying to read from a ppm file and this is basicly the code i am using to do so.
when i compile it there is no errors
However when i try to build the object i get some weird errors like inappropriate types used
the basic sample for my code is


#include <fstream.h>
#include <iostream.h>

LPTSTR filename;
filename = &quot;inputfile.txt&quot;;
ifstream file;
file.open(filename);

LPTSTR header, colour;
int width, height;
file >> header;
file >> width;
file >> height;
file >> colour;

file.close();

the errors i get are

error LNK2001: unresolved external symbol &quot;__declspec(dllimport) public: void __thiscall ifstream::`vbase destructor'(void)&quot; (__imp_??_Difstream@@QAEXXZ)
ezrgb24.obj : error LNK2001: unresolved external symbol &quot;__declspec(dllimport) public: void __thiscall ifstream::close(void)&quot; (__imp_?close@ifstream@@QAEXXZ)
ezrgb24.obj : error LNK2001: unresolved external symbol &quot;__declspec(dllimport) public: int __thiscall ios::eof(void)const &quot; (__imp_?eof@ios@@QBEHXZ)
ezrgb24.obj : error LNK2001: unresolved external symbol &quot;__declspec(dllimport) public: class istream & __thiscall istream::eek:perator>>(int &)&quot; (__imp_??5istream@@QAEAAV0@AAH@Z)
ezrgb24.obj : error LNK2001: unresolved external symbol &quot;__declspec(dllimport) public: class istream & __thiscall istream::eek:perator>>(char *)&quot; (__imp_??5istream@@QAEAAV0@PAD@Z)
ezrgb24.obj : error LNK2001: unresolved external symbol &quot;__declspec(dllimport) public: void __thiscall ifstream::eek:pen(char const *,int,int)&quot; (__imp_?open@ifstream@@QAEXPBDHH@Z)
ezrgb24.obj : error LNK2001: unresolved external symbol &quot;__declspec(dllimport) public: static int const filebuf::eek:penprot&quot; (__imp_?openprot@filebuf@@2HB)
ezrgb24.obj : error LNK2001: unresolved external symbol &quot;__declspec(dllimport) public: __thiscall ifstream::ifstream(void)&quot; (__imp_??0ifstream@@QAE@XZ)
.\Debug\ezrgb24.ax : fatal error LNK1120: 8 unresolved externals



can anybody enlighten me on what i am doing wrong or what the erros mean? and am i delaring a string correctly?
 
To be honest, I'm not quite sure how you've managed this! The problem has nothing to do with file handling - it's a linking problem. The compiler cannot find the library containing the file stream classes you're referencing in your code. Whenever you see 'error LNK2001' then you know that the problem is linking, and not a syntax error.

I tried to recreate your error messages by creating a simple Visual C++ Win32 project and pasting your code into WinMain, then in project settings I removed all linked library modules. The project still compiled!

Bin the existing project and create a new one by going to File->New and under the Projects tab select Win32 Application. That should sort it.

Phil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top