#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")