Code::Blocks 13.12 problem
What is wrong?
I get this message from the "Build messages" tab:
In function `_startĀ“:
undefined reference to `mainĀ“
main.cpp
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
|
#include <iostream>
#include <string>
#include <fstream>
#include <limits>
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;
}
|
fcreate.h
1 2 3 4 5 6 7 8 9 10 11
|
#ifndef FCREATE_H
#define FCREATE_H
class fcreate
{
public:
fcreate();
};
#endif // FCREATE_H
|
fcreate.cpp
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
|
#include "fcreate.h"
#include <iostream>
#include <string>
#include <fstream>
fcreate::fcreate()
{
std::string filename, mname;
int hp;
std::cout << "What is the file name going to be? ";
std::cin >> filename;
std::ofstream monsterc;
monsterc.open(filename.c_str());
std::cout << "What is the monsters name? ";
std::cin >> mname;
monsterc << mname << std::endl;;
std::cout << "How much h[code]
[/CODE]p will it have? ";
std::cin >> hp;
monsterc << hp;
monsterc.close();
}
|
The class is not needed yet, but I will make a menu soon and there I will need it.
Last edited on
Line 11:
1 2
|
// return file
return file ; // *** add missing semicolon
|
And if there are multiple files
main.cpp lying around, make sure you are compiling the right file.
Last edited on
Topic archived. No new replies allowed.