Reputation: 602
I found that I was using the same code over and over again throughout my program. To improve efficiency etc, I decided that I would impliment a File-Handling class which would allow me to interact with all of my files.
On creating this - I am getting strange errors which I cannot decipher. Eg:
Error 11 error LNK1169: one or more multiply defined symbols found C:\Users\JG\Desktop\ProjectWork\ConsoleApplication1\Debug\ConsoleApplication1.exe 1 1 ConsoleApplication1
and
Error 8 error LNK2005: "bool __cdecl bolFileExist(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?bolFileExist@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in Draw.obj C:\Users\JG\Desktop\ProjectWork\ConsoleApplication1\ConsoleApplication1\Player.obj ConsoleApplication1
I can only put this down to the code in the Filez.h
file as commenting all of the associated code it builds and runs fine. I have done some re-search into this and have drawn a blank sadly.
I would very much appreciate some feedback on this code - and some pointers as to what I am doing wrong.
string getFinalLineOfFile(string FileLoction)
{
//http://bit.ly/1j6h6It
string line = " ";
string subLine;
ifstream readFile(FileLoction);
string found_DrawID; //Username in the file;
while (getline(readFile,line)) {
stringstream iss(line);
//We are only Interested in the First Value
iss >> subLine;
}
//The Value at CurrentDrawID will be the final value in the file;
return subLine;
}
bool bolFileExist(string FileLocation)
{
//If that Exists. Return it.
ifstream readFile(FileLocation);
return readFile;
}
bool itemExistLineOne(int find, string FileLocation)
{
string line = " ";
//ifstream readFile(".//Draws//Draws.txt");
ifstream readFile(FileLocation);
string foundID; //Username in the file;
while (getline(readFile,line)) {
stringstream iss(line);
iss >> foundID;
//Covert the Integer input to a String for comparison.
if (to_string(find) == foundID) {
return true;
}
}
return false;
}
void CreateNewFileLine(string Location, string text){
ofstream output_file(Location, ios::app);
if (!output_file.is_open()) { // check for successful opening
cout << "Output file could not be opened! Terminating!" << endl;
}
else{
output_file << text;
output_file << endl; //Create new line at the end of the file.
output_file.close();
}
}
Many thanks,
Upvotes: 0
Views: 135
Reputation:
You are likely missing 'inline' in some header:
struct X { void f(); };
inline void X::f() {} // will be multiply defined without inline.
End of that header
Upvotes: 2