源碼
#include <strstream>
#include <iostream>
using namespace std;
int main()
{
strstream* s = new strstream();
cin>> s ;
cout << "test is " << s << endl;
return 0;
}
編譯
gcc -o test test.cpp
報錯
C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
我看了別人的代碼也是這麼用的,但怎麼就不報錯嗎?是編譯器選項的問題嗎(不是說加上-Wno-deprecated)?
答案1
因爲 strstream 是非標準的,在C++標準制定之前曾經被使用過,現在新版本的編譯器一般已經不再提供對它的支持了。應該使用 stringstream,對應的頭文件爲<sstream>。
答案2
strstream已經被stringstream取代,在sstream頭文件中定義..
答案3
應該使用stringstream,放棄strstream
就是在CXX_FLAGS中添加-std=c++0x 以及 -Wno-deprecated這兩個選項
#include <strstream>
#include <iostream>
using namespace std;
int main()
{
strstream* s = new strstream();
cin>> s ;
cout << "test is " << s << endl;
return 0;
}
編譯
gcc -o test test.cpp
報錯
C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
我看了別人的代碼也是這麼用的,但怎麼就不報錯嗎?是編譯器選項的問題嗎(不是說加上-Wno-deprecated)?
答案1
因爲 strstream 是非標準的,在C++標準制定之前曾經被使用過,現在新版本的編譯器一般已經不再提供對它的支持了。應該使用 stringstream,對應的頭文件爲<sstream>。
答案2
strstream已經被stringstream取代,在sstream頭文件中定義..
答案3
應該使用stringstream,放棄strstream
如果使用的話,還有報錯。
報錯與警告的解決方案:
- set(CMAKE_CXX_FLAGS "-std=c++0x -Wno-deprecated")
這兩個選項的意思:c++0x是新的C++意思。而-Wno-deprecated是表示 no-deprecated這類警告忽略。