Reputation: 101
been banging my head on the table over this all night.
I'm simply trying to declare an ifstream object like so....
ifstream inputStream;
I'm getting this error:
Error 5 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >::operator*(void)const " (??D?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEABDXZ) C:\Users\Julz\Desktop\My Dropbox\3rdYear\2ndSemester\Games Prog\Game\DemocracyInvaders\Score.obj DemocracyInvaders
I can declare it as a pointer like so...
ifstream *inputStream;
but that just goes on to headaches when I try to read in file data and I figure I should work out why the basic declaration isn't working before trying some hacked out fix.
I'm using SDL and have the following includes in a header a few files down...
#ifndef SDL_GRAPHICS_H //just a class I'm using to initialise my SDL stuff
#define SDL_GRAPHICS_H
#include <stdio.h>
#include <iostream>
#include <vector>
#include <fstream>
#include "SDL.h"
#include "SDL_ttf.h"
I've tried swapping the SDL includes above the C++ stuff and all sorts of variations, nothing. My header includes are all in the right order and I'm thinking that if there was a problem with includes I couldn't declare the ifstream as a pointer?
oh, I've tried using fstream and even just declaring ofstream, all the same error. also, it doesn't matter what class (source or header) I try it in, always the same. Even tried declaring it in my driver (main) file with the includes directly in it, no dice... Totally lost here!
Upvotes: 1
Views: 1617
Reputation: 754555
It looks like you are failing to link the C runtime into your application. When declared as a non-pointer you bring in at least the constructor of the ifstream
class into your application. It appears that the constructor calls a function which is a part of the C-runtime and hence you end up with a linking error.
Upvotes: 7