2013-12-14 87 views
0

我發現我在整個程序中反覆使用相同的代碼。爲了提高工作效率等,我決定啓用一個文件處理類,它允許我與所有文件進行交互。C++文件處理類

在創建這個 - 我得到奇怪的錯誤,我不能解碼。例如:

Error 11 error LNK1169: one or more multiply defined symbols found C:\Users\JG\Desktop\ProjectWork\ConsoleApplication1\Debug\ConsoleApplication1.exe 1 1 ConsoleApplication1 

Error 8 error LNK2005: "bool __cdecl bolFileExist(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" ([email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) already defined in Draw.obj C:\Users\JG\Desktop\ProjectWork\ConsoleApplication1\ConsoleApplication1\Player.obj ConsoleApplication1 

我只能把這個下來的代碼在Filez.h文件註釋所有它建立並運行良好的相關代碼。我已經對此做了一些重新研究,並且悲傷地畫了一個空白。

我非常感謝這段代碼的一些反饋 - 以及一些關於我做錯了什麼的指針。

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(); 
    } 


} 

非常感謝,

+0

確保這些功能定義在一個CPP文件不在標題中。 – drescherjm

回答

2

你很可能在一些頭失蹤「內聯」:

struct X { void f(); }; 
inline void X::f() {} // will be multiply defined without inline. 

該頭的結束

+0

感謝您的解決方案 - 讚賞。我所做的就是將所有功能「內聯」,這就解決了問題! – KingJohnno