C++ C++;文件处理类
我发现我在整个程序中反复使用相同的代码。为了提高效率等,我决定实现一个文件处理类,该类允许我与所有文件交互 在创造这一点上,我得到了我无法破译的奇怪错误。例如:C++ C++;文件处理类,c++,compiler-errors,file-handling,C++,Compiler Errors,File Handling,我发现我在整个程序中反复使用相同的代码。为了提高效率等,我决定实现一个文件处理类,该类允许我与所有文件交互 在创造这一点上,我得到了我无法破译的奇怪错误。例如: Error 11 error LNK1169: one or more multiply defined symbols found C:\Users\JG\Desktop\ProjectWork\ConsoleApplication1\Debug\ConsoleApplication1.exe 1 1 Conso
Error 11 error LNK1169: one or more multiply defined symbols found C:\Users\JG\Desktop\ProjectWork\ConsoleApplication1\Debug\ConsoleApplication1.exe 1 1 ConsoleApplication1
及
非常感谢,您可能在某些标题中缺少“inline”:
struct X { void f(); };
inline void X::f() {} // will be multiply defined without inline.
该标题结束感谢您的解决方案-非常感谢。我所做的是把所有的函数都放到“内联”中,这就解决了问题!确保这些函数定义位于cpp文件中,而不是标头中。
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();
}
}
struct X { void f(); };
inline void X::f() {} // will be multiply defined without inline.