当我们在Visual Studio 2013(C++控制台应用程序),Os-Winsever2008(64位)中使用fscanf_s方法时,文件指针提前读取一个或两个字节的数据。 例如:在读取文本文件时,文件的第二行是“Administartor”,但fscanf_s()将该单词作为“dministrator”返回。 请帮我解决这个问题。 代码是使用Visual Studio 2008fscanf_s在Winserver2008中无法正常工作VS2013 64位
FILE* pFile;
pFile = NULL;
string strFile = "E:\\10_Products.lrf";
fopen_s(&pFile, strFile.c_str(), "r");
char szTemp[256];
string strTemp = "";
if (NULL != pFile)
{
while (!feof(pFile))
{
nRet = fscanf_s(pFile, "%s", szTemp);
if (EOF == nRet)
{
cout << "EOF detected";
}
}
return 0;
}
10_Products.lrf文件的格式如下工作正常的Windows XP 32位。
[OPERATOR_LEVEL]
Administrator
向我们显示您的代码。 –
示例代码 \t FILE * pFile; \t pFile = NULL; \t string strFile =“E:\\ 10_Products.lrf”; \t fopen_s(&pFile,strFile.c_str(),“r”); \t char szTemp [256]; \t string strTemp =“”; \t如果(NULL = PFILE!) \t \t { \t \t而(FEOF(PFILE)!) \t \t { \t \t \t NRET = fscanf_s(PFILE, “%s” 时,szTemp); \t \t \t如果(EOF == NRET) \t \t \t { \t \t \t \t COUT << “EOF检测到的”; \t \t \t} \t} \t返回0; } –
你应该编辑你的文章,而不是将其添加为评论 –