C++文件处理类
C++ file Handling class
我发现我在整个程序中一次又一次地使用相同的代码。为了提高效率等,我决定实现一个文件处理类,它将允许我与所有文件交互。
在创建这个过程中,我遇到了一些我无法破解的奇怪错误。例如:
Error 11 error LNK1169: one or more multiply defined symbols found C:UsersJGDesktopProjectWorkConsoleApplication1DebugConsoleApplication1.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> >)" (?bolFileExist@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in Draw.obj C:UsersJGDesktopProjectWorkConsoleApplication1ConsoleApplication1Player.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();
}
}
非常感谢,
您可能在某些标头中缺少"inline":
struct X { void f(); };
inline void X::f() {} // will be multiply defined without inline.
该标头的末尾
相关文章:
- 如何在 c++ 窗口中将参数和返回的退出值传递到批处理文件/从批处理文件获取返回的退出值
- 从之前添加的批处理文件中删除单词
- 无法从C++ Windows 服务执行批处理文件
- 处理文件期间输出失真.wav
- TOCTTOU - 在处理文件之前使用访问权限
- 如何将批处理文件的输出读取到C 中的字符串中
- cmake:生成批处理文件调用cl.exe
- 处理文件行流迭代器
- 如何运行批处理文件和读取输出
- 用文本处理文件
- GetCommandLine():无法从批处理文件(GCC-Compiler)传递多行参数
- exe文件不被识别为内部或外部命令,可操作的程序或批处理文件在C++
- 您如何使用System()调用带有引号的参数的批处理文件
- Visual Studio C - 无法输出预处理文件
- 重命名批处理文件(删除名称中的一些符号)(python/matlab/shell)
- Dokan:我应该自己处理文件共享和访问权限吗?
- C++处理文件,在制作程序时遇到麻烦
- 对桌面进行了更改.ini使用批处理文件,但文件夹图标不会更改
- 如何将字符串转换为批处理文件中的整数
- 为什么我不能在Windows Server 2008中使用System()从服务启动批处理文件