我正在跟随C++ Primer这本书,并尝试所有的代码示例。 我对这个例子很感兴趣:
#include <iostream>
#include <string>
using std::string;
using std::cin;
using std::cout;
using std::endl;
int main()
{
string line;
while (getline(cin,line))
cout << line << endl;
return 0;
}
编译这段代码之前,我本以为它会失败,因为我没有使用
while (std::getline(cin,line))
为什么getline在全局命名空间中? 据我所知,只有在使用了
时才会发生这种情况。据我所理解,只有当使用该函数时才会发生这种情况。
namespace std;
using std::getline;
我在Linux Mint Debian Edition上使用g++版本4.8.2。