user-0 提问: WritePrivateProfileString函数不能写入ini文件

回复:
user: user-0
content: 引用 3 楼 u011623102 的回复:是不是D:/set.ini的问题 改成D:\\set.ini试下 不是这个问题，我查了一下斜杠是用在linux下的，反斜杠是win下，不过都能用！

user: user-0
content: 引用 1 楼 user-3 的回复:1. 这种写法是没问题的啊， 我刚才试了一下，可以成功写入数据。楼主可以把对应的代码贴出来看看 2. 直接createfile 创建.ini文件就行  代码就刚刚的一句话： int main()[     int res;     res = ......;     printf("res = %d",res);     return 0; ]

user: user-1
content: 是不是D:/set.ini的问题 改成D:\\set.ini试下

user: user-2
content: WritePrivateProfileString The WritePrivateProfileString function copies a string into the specified section of the specified initialization file.   This function is provided for compatibility with 16-bit Windows-based applications. WIn32-based applications should store initialization information in the registry.   BOOL WritePrivateProfileString(   LPCTSTR lpAppName,  // pointer to section name   LPCTSTR lpKeyName,  // pointer to key name   LPCTSTR lpString,   // pointer to string to add   LPCTSTR lpFileName  // pointer to initialization filename );   Parameters lpAppName  Pointer to a null-terminated string containing the name of the section to which the string will be copied. If the section does not exist, it is created. The name of the section is case-independent; the string can be any combination of uppercase and lowercase letters.  lpKeyName  Pointer to the null-terminated string containing the name of the key to be associated with a string. If the key does not exist in the specified section, it is created. If this parameter is NULL, the entire section, including all entries within the section, is deleted.  lpString  Pointer to a null-terminated string to be written to the file. If this parameter is NULL, the key pointed to by the lpKeyName parameter is deleted.  Windows 95: The system does not support the use of the TAB (\t) character as part of this parameter.   lpFileName  Pointer to a null-terminated string that names the initialization file.  Return Values If the function successfully copies the string to the initialization file, the return value is nonzero.  If the function fails, or if it flushes the cached version of the most recently accessed initialization file, the return value is zero. To get extended error information, call GetLastError.   Remarks Windows 95: Windows 95 keeps a cached version of WIN.INI to improve performance. If all three parameters are NULL, the function flushes the cache. The function always returns FALSE after flushing the cache, regardless of whether the flush succeeds or fails.  A section in the initialization file must have the following form:   [section] key=string       .       .       .    If the lpFileName parameter does not contain a full path and filename for the file, WritePrivateProfileString searches the Windows directory for the file. If the file does not exist, this function creates the file in the Windows directory.   If lpFileName contains a full path and filename and the file does not exist, WriteProfileString creates the file. The specified directory must already exist.   Windows NT: Windows NT maps most .INI file references to the registry, using the mapping defined under the following registry key:  HKEY_LOCAL_MACHINE\Software\Microsoft\ Windows NT\CurrentVersion\IniFileMapping   Windows NT keeps a cache for the IniFileMapping registry key. Calling WritePrivateProfileStringW with the value of all arguments set to NULL will cause Windows NT to refresh its cache of the IniFileMappingKey for the specified .INI file.

user: user-3
content: 1. 这种写法是没问题的啊， 我刚才试了一下，可以成功写入数据。楼主可以把对应的代码贴出来看看 2. 直接createfile 创建.ini文件就行