0

I am new to C++ Programming, and I initially learned my basics in VS 2010. I upgraded to VS2013, and I tried to declare my ifstream/ofstream variables. It would fail to build my program until I either deleted or commented them out. The code below is just the header file which I'm defining a class which I intend to inherit and save variables from a parent class (character). All of the following includes are in my CPP.

Thanks to those already answered, I removed the istream, and my namespace was present, but I failed to mentioned that and I apologize for my lack of clarity. However, the program is still producing the previously noted errors.

    #include <iostream>
    #include <string>
    #include <ctime>
    #include <limits>
    #include <Windows.h>
    #include <cmath>
    #include <fstream>
    #include <iomanip>

    using namespace std;

    class saveLoad : public character 
    { 
        public:     
        saveLoad();     
        void saveGameFunc();    
        void loadGameFunc();

        ifstream loadGame;  
        ofstream saveGame;
     };

The Errors I receive are:

Error 39 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator > >::operator*(void)const " (??D?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@QBEABDXZ) E:\Text Rpg\Text Rpg\Game.obj Text Rpg

and

Error 40 error LNK1120: 1 unresolved externals E:\Text Rpg\Debug\Text Rpg.exe 1 1 Text Rpg

Can someone please explain to me the proper way to declare/define in-file and out-file in VS2013?

Uooo
  • 6,204
  • 8
  • 36
  • 63
4eWatts
  • 11
  • 1
  • This code in its current form is not even a valid C++. – Mateusz Grzejek Apr 19 '15 at 20:59
  • Your code compiles just fine in Visual Studio 2013 for me after I added an empty character class, provided empty implementations for the 3 functions listed in the saveload class, and added a main function. This means the error is in the code you did not show us. Please construct a short complete example of the problem and edit it into the question. – Retired Ninja Apr 20 '15 at 00:46
  • You might also read the answers here: http://stackoverflow.com/questions/11919836/unresolved-external It's likely your project is setup incorrectly. – Retired Ninja Apr 20 '15 at 01:34
  • My Project was setup incorrectly. After Reviewing your recommended thread, My program now compiles. Thank you for help, it's greatly appreciated! – 4eWatts Apr 20 '15 at 16:06

2 Answers2

0

Shouldn't those be std::ifstream and std::ofstream?

Unless you have using std::ifstream and using std::ofstream in that file but didn't post it. Both std::ifstream and std::ofstream are within the <fstream> header, so you don't actually need the <istream> one, unless you're using it for something else.

You also have a compiler error here:

ofstream saveGame:

Which should be:

ofstream saveGame;
bobroxsox
  • 902
  • 2
  • 10
  • 26
0

You are not declaring namespace try changing

ifstream loadGame;
ofstream saveGame;

to

std::ifstream loadGame;
std::ofstream saveGame;