关于C++中 命名空间域的问题? 请教高手.

来源:百度知道 编辑:UC知道 时间:2024/06/08 19:35:39
#include<sstream>
#include <iostream>
using namespace std;
void main()
{
ostringstream buffer;
buffer << "abc" <<endl;
buffer << "abc";
cout << buffer.str() << endl;
}

cout << buffer.str() << endl;中的 buffer.str() 是怎么回事?
是不是在声明using namespace std;中默认了什么东西啊?不然.只声明没定义的话,没什么用吧
如果是有默认的话.求using namespace std;中的原默认的详解.
本人的C++才入门啊 而这个题目也是书上的,想了甚久.就是不明白,
还是求详解啊;

使用using namespace std是因为你用到了STL的头文件,而又想避免每次使用其中的函数时都在前面加上std::所以才有了这个声明。
想知道buffer.str()什么意思,可以去看STL,还有很多其他的内容。不仅仅是这个。。

不用的话是这样的
#include<sstream>
#include <iostream>
//using namespace std;
void main()
{
std::ostringstream buffer;
buffer << "abc" << std::endl;
buffer << "abc";
std::cout << buffer.str() << std::endl;
}