strstream 与 backward_warning.h 的警告问题

来源:互联网 发布:网络结构图图标 编辑:程序博客网 时间:2024/06/05 05:20

如果我们遇到:

.......\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>

此类的警告,多半会理解为include头文件,加不加".h"的问题


但是如果警告报在了 #include<strstream> 上面,又没有".h",如果处理

此时头文件修改为 sstream即可,这也是微软推荐使用的


这需要提及strstream与sstream的区别,了解区别了,考虑是否修改;


在C++有两种字符串流,也称为数组I/O流,一种在sstream中定义,
另一种在strstream中定义。
它们实现的东西基本一样。

strstream里包含
class strstreambuf;
class istrstream;
class ostrstream;
class strstream;
它们是基于C类型字符串char*编写的

sstream中包含
class istringstream;
class ostringstream;
class stringbuf;
class stringstream;
class …….
它们是基于std::string编写的

因此ostrstream::str()返回的是char*类型的字符串
而ostringstream::str()返回的是std::string类型的字符串

在使用的时候要注意到二者的区别,一般情况下推荐使用std::string类型的字符串
当然如果为了保持和C的兼容,使用strstream也是不错的选择。
但要记住一点,strstream虽仍然是C++语言标准的一部分,但已被C++标准宣称为“deprecated”,也就是不再提倡使用了,也说不定以后干粹就没了

原创粉丝点击