C++"使用"运算符使标准数据障碍的对象可用
C++ 'using' operator to make object of std available
请看一下我的代码:
#include <iostream>
using std::cin; // I would like to make cin object available
using std::cout; // I would like to make cout object available in source code
using std::get; // I would like to make cin.get() available
using std::fail; // I would like to make cin.fail() available
factorial(int number);
int main()
{
int closer;
cin >> closer;
while (!cin.fail())
{
factorial(closer); // it's obvious going by the name, It's factorial function
cin >> closer;
}
}
factorial(int number)
{
// the function is correct and it's been examined before....
}
我在linux中使用gcc,有这个错误:
factor.cpp:8:12: error: ‘std::get’ has not been declared
factor.cpp:9:12: error: ‘std::fail’ has not been declared
是否有错别字或逻辑错误
您不需要使用using
作为成员函数,它们可以毫无问题地使用:
#include <iostream>
using std::cin; // I would like to make cin object available
using std::cout; // I would like to make cout object available in source code
factorial(int number);
int main()
{
int closer;
cin >> closer;
while (!cin.fail()) // fail is part of the cin type and not part of the std namespace
{
factorial(closer); // it's obvious going by the name, It's factorial function
cin >> closer;
}
}
factorial(int number)
{
// the function is correct and it's been examined before....
}
相关文章:
- 使用指针访问数组中的对象数据成员
- 如果在 C++ 构造函数中以错误的顺序初始化对象数据,会发生什么类型的错误
- 只需调用对象即可获取对象数据
- 从R中访问C 对象数据成员
- C 如何将对象数据传递到用户定义的转换操作员中
- 通用B树,用于存储自定义对象/数据类型
- 通过指向对象数据成员的指针更改该对象的值
- C .更改对象数据成员的数据成员
- 排序类对象数据成员从大到小
- 从程序集中调用的C++方法返回对象数据
- 如何设置对象数据成员与这个c++与这个
- 访问私有对象数据时出现问题
- 流操作,用于以不同格式输出对象数据
- 更新标准::映射对象数据
- C++是保证在基本对象std::swap之后有效的派生对象数据
- 添加类的对象数据
- 将对象/数据从库传递到控制台应用程序(如何)
- 将一个对象数据复制到另一个相同类型 C++ 的对象
- 用c++将对象数据写入txt文件
- c++继承.更改对象数据类型