在C++遇到有些關鍵字或者函數被棄用的情況,比如xxx was declared deprecated

在C++遇到有些關鍵字或者函數被棄用的情況

隨着每一次C++的不斷更新,可能都會有些函數或者關鍵字會被棄用,或者換成了其他的名字,這在編寫代碼的時候經常會碰到,碰到這種情況,可以在代碼的第一行寫上忽略此錯誤的句子,一般爲:

#pragma  warning(disable:錯誤編號)

如:下面這段代碼中使用了strdup(),此函數的功能是講函數中的數據拷貝到另一個變量中,這是調試程序會出現下面的錯誤:

錯誤 1 error C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details. d:\c++workspace\consoleapplication5\consoleapplication5\consoleapplication5.cpp 30 1 ConsoleApplication5

此錯誤的編號是4996

所以我們要調試成功,可以這樣寫代碼:

#pragma  warning(disable:4996)

代碼添加位置:

#include "stdafx.h"
#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>

轉載於:http://www.cnblogs.com/pengjun-shanghai/p/4825227.html

發佈了40 篇原創文章 · 獲贊 13 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章