Why does this work?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <string>
#include <fstream>
#include <limits>
#include "fcreate.h"
std::fstream& GotoLine(std::fstream& file, unsigned int num){
file.seekg(std::ios::beg);
for(int i=0; i < num - 1; ++i){
file.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}
return file;
}
int main()
{
std::string filename, trash, mname;
int hp;
std::cout << "Enter filename: ";
std::cin >> filename;
std::fstream monster(filename.c_str());
monster >> trash >> mname;
GotoLine(monster, 2);
monster >> trash >> hp;
monster.close();
std::cout << mname << " has " << hp << " hp" << std::endl;
return 0;
}
|
but when I add a class it doesn't
fcreate.cpp
1 2 3 4 5 6 7
|
#include <iostream>
#include "fcreate.h"
fcreate::fcreate()
{
std::cout << "BUG";
}
|
Build messages:
In function `_startĀ“:
undefined reference to `mainĀ“
I can't edit the 1st post that's why I made a new one. I can't even post a reply
Last edited on
Are you compiling and linking those two files simultaneously? Are you sure htat you do not just try to link second one alone?
I don't manually compile I use code::blocks build & run button, I fixed it by un-install code::block and install it back.
I have no idea why it didn't work before.
Are both files are set to compile? Are they in the same project?
Yes, but I have no problem anymore I un-installed c::b and installed it back and I have no problems anymore.