¿No puede declarar el objeto fstream? pero ¿se puede declarar como puntero?

been banging my head on the table over this all night.

I'm simply trying to declare an ifstream object like so....

ifstream inputStream;

Recibo este 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

#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!

preguntado el 08 de noviembre de 11 a las 15:11

1 Respuestas

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.

respondido 08 nov., 11:19

Or failing to link the correcta CRT. __imp___CrtDbgReportW looks like something that's specific to the Debug CRT. - MSalters

Amazing, thank you so much. I had the wrong threading (thing) set in the runtime library. I just had it set to the lazy foo suggested setting for using SDL, I just set it to inherit from parent (or some such option) and Robert's your aunties live in lover!! - Julz

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.