此功能或变量可能不安全 [英] This function or variable may be unsafe

查看:152
本文介绍了此功能或变量可能不安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS   
















#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#include "IInvFile.h"
namespace SearchEngine_Project {
// Integrated Inverted Index (see lecture notes on Implementation)
IInvFile InvFile4;

int main3() {
        char tmp[10000];
        char str[1000];
        int docid;
        int loc;
        int cnt=0;
        FILE * fp = fopen("C:/Users/user/Documents/Visual Studio 2012/Projects/new4/const.txt", "rb");
        if (fp == NULL) {
                printf("Cannot open file \r\n");
                return 1;
                }

        // Initialize the Hash Table
        InvFile4.MakeHashTable(13023973);

        while(fgets(tmp,10000,fp) != NULL) {
                // Get the stem, the document identifier and the location
                sscanf(tmp,"%s %d %d", &(str[0]), &docid, &loc);

                // Add posting into the Integrated Inverted index
                // See lecture notes on Implementation
                InvFile4.Add(str, docid, 1);

                // Keep us informed about the progress
                cnt++;
                if ((cnt % 100000) == 0) printf("Added [%d]\r\n",cnt);
        }

        printf("Saving inverted file ...\r\n");
        InvFile4.Save("InvFile.txt");

        InvFile4.Clear();
        fclose(fp);
        return 0;
}
}

推荐答案

警告信息非常明确:

'fopen':这个函数或变量可能不安全。考虑使用fopen_s代替。



见这里: http://msdn.microsoft.com/en-us/library/ttcz0bys.aspx [ ^ ]



这意味着新代码不建议使用 fopen ,因为它可能会从未来版本中删除,并被更新,更好的版本所取代 - 在此case fopen_s



要么使用它建议的更现代的等价物,要么禁用警告(我会去第一个选项,我自己)
The warning message is quite explicit:
"'fopen': This function or variable may be unsafe. Consider using fopen_s instead."

See here: http://msdn.microsoft.com/en-us/library/ttcz0bys.aspx[^]

What it means is that fopen is not recommended for new code, as it may be removed from future version, having been superceeded by a newer, better version - in this case fopen_s

Either use the more modern equivalent as it suggests, or disable the warning (I'd go with the first option, myself)


这篇关于此功能或变量可能不安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆