为什么得不到正确的结果

yyz2000 2003-05-30 12:24:54
我的yyz1.ini文件内容如下
[接车]
正常过车=3
————————————————————————
int j;
char buffer[20];
GetPrivateProfileString("接车",str,"正常过车",buffer,10,"d:\\xuexi\\yyz1.ini");
j=atoi(buffer);
__________________________________________
为什么j返回的值不是3
...全文
61 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
squall220 2003-05-30
  • 打赏
  • 举报
回复
char str[10];
int i=20;
itoa(i,str,10);
WritePrivateProfileString("接车","正常过车",str,"d:\\xuexi\\yyz1.ini");
上面的语句写错了:

GetPrivateProfileString("接车","正常过车"," ",buf,"d:\\xuexi\\yyz1.ini");

squall220 2003-05-30
  • 打赏
  • 举报
回复
老大用法错了:
GetPrivateProfileString("接车","正常过"," ",buf,,"d:\\xuexi\\yyz1.ini");
j=atoi(buf)
另外最好用GetPrivateProfileInt,省了一部atoi啊!
yyz2000 2003-05-30
  • 打赏
  • 举报
回复
另外我怎样将整形数据转变成字符型数据在写回原来的位置
mlin2000 2003-05-30
  • 打赏
  • 举报
回复
DWORD GetPrivateProfileString(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
LPCTSTR lpDefault, // default string
LPTSTR lpReturnedString, // destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // initialization file name
);
Parameters
lpAppName
[in] Pointer to a null-terminated string that specifies the name of the section containing the key name. If this parameter is NULL, the GetPrivateProfileString function copies all section names in the file to the supplied buffer.
lpKeyName
[in] Pointer to the null-terminated string specifying the name of the key whose associated string is to be retrieved. If this parameter is NULL, all key names in the section specified by the lpAppName parameter are copied to the buffer specified by the lpReturnedString parameter.
lpDefault
[in] Pointer to a null-terminated default string. If the lpKeyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the lpReturnedString buffer. This parameter cannot be NULL.
Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedString buffer to strip any trailing blanks.

Windows 95: Although lpDefault is declared as a constant parameter, the system strips any trailing blanks by inserting a null character into the lpDefault string before copying it to the lpReturnedString buffer.

Windows NT/2000: The system does not modify the lpDefault string. This means that if the default string contains trailing blanks, the lpReturnedString and lpDefault strings will not match when compared using the lstrcmp function.

lpReturnedString
[out] Pointer to the buffer that receives the retrieved string.
nSize
[in] Specifies the size, in TCHARs, of the buffer pointed to by the lpReturnedString parameter.
lpFileName
[in] Pointer to a null-terminated string that specifies the name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.
mlin2000 2003-05-30
  • 打赏
  • 举报
回复
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
mlin2000 2003-05-30
  • 打赏
  • 举报
回复
BOOL WritePrivateProfileString(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
LPCTSTR lpString, // string to add
LPCTSTR lpFileName // initialization file
);
Parameters
lpAppName
[in] 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
[in] 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
[in] 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
[in] Pointer to a null-terminated string that specifies the name of the initialization file.

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧