文件写入/读取不工作
File Writing / Reading is not working
我最近采用了一种注入到进程的新方法,除了配置读取/文件读取之外,一切都很好。这是我当前使用的代码:
string ReadIniKey(string section, string key){
string iniPath = GetDocuments()/*This returns the correct value)*/ + "My Program\Config.ini";
if (!ifstream(iniPath)){ ofstream file(iniPath); WriteINIDefaults(); }
char retVal[255];
GetPrivateProfileString((LPCWSTR)section.c_str(), (LPCWSTR)key.c_str(), (LPCWSTR)"", (LPWSTR)retVal, 255, (LPCWSTR)iniPath.c_str());
return retVal;
}
void WriteIni(string section, string key, string value){
string iniPath = GetDocuments()/*This returns the correct value)*/ + "My Program\Config.ini";
if (!ifstream(iniPath)) ofstream file(iniPath);
WritePrivateProfileString((LPCWSTR)section.c_str(), (LPCWSTR)key.c_str(), (LPCWSTR)value.c_str(), (LPCWSTR)iniPath.c_str());
}
它没有读取文件,创建文件或向现有文件写入任何内容。我被注入到一个64位进程中,有任何可能的修复吗?我主要关心的是GetPrivateProfileString/writepprivateprofilestring部分。
EDIT:在发布模式下编译它会创建文件,但是GetPrivateProfileString/writepprivateprofilestring不会对文件做任何事情
构造函数ifstream()
不接受c++ string
。取const char*
,即C
型char/string
。但是如果你正在使用C++11
,那么在ifstream()
构造函数中使用string
应该不会有问题。
因此将ifstream(iniPath)
更改为ifstream(iniPath.c_str())
或使用C
样式字符串
我得到它固定使用GetPrivateProfileStringA &writepprivateprofilestringa代替GetPrivateProfileString &WritePrivateProfileString
文件读写不正常
相关文章:
- 我的文件无法正常工作,无法从C++文件中读取上下文
- 尝试读取/写入Graphviz DAG值的工作证明会导致segfault
- 读取二进制文件大小的短自上周以来停止工作
- Linux C++读取 UART 设备无法始终如一地工作
- char* 如何读取十六进制的这个整数?它在 ostream::write() 中是如何工作的
- 从工作目录 QtWebEngine 读取文件
- 为什么将uint8_t读取为十六进制没有按预期工作?
- ifstream读取二进制文件在发行模式下工作,但在调试模式下不使用
- C++程序在 freopen 中读取大文本后停止工作
- 读取进程内存无法正常工作,使用 UTF16 字符串
- 当写和读在不同的文件中时,C++二进制读取会产生segfault,但放在一个文件中的相同代码可以工作
- 我无法获得基于读取字符数组的算法来工作
- CMD窗口停止工作,文本文件使用fstream读取错误
- USB串行虚拟COM端口:读取不工作,但写入工作
- 似乎没有任何读取文件的方法可以工作,所有方法都不返回任何东西-C++
- 从文件 C++ 程序读取停止工作
- 正在从工作目录C++中的文件夹中读取
- c++中的文件读取:for和while嵌套循环没有按预期工作:串行
- C++:使用get()读取文件;没有按预期工作
- std::getline() 访问冲突,以前可以工作,但现在无法从任何文件中读取