📜  C++中的ios操纵器oct()函数

📅  最后修改于: 2021-05-30 12:56:20             🧑  作者: Mango

C++中的流操纵器oct()方法用于为指定的str流设置基线格式标志。该标志设置八进制数字的基线。因此,输出以八进制为单位显示数字。

句法:

ios_base& oct (ios_base& str)

参数:此方法接受str作为参数,这是影响格式标志的流。

返回值:该方法返回设置了内部格式标志的流str。

范例1:

// C++ code to demonstrate
// the working of oct() function
  
#include 
  
using namespace std;
  
int main()
{
  
    // Initializing the number
    int n = 321;
  
    // Using oct()
    cout << "oct flag: "
         << oct << n << endl;
  
    return 0;
}
输出:
oct flag: 501

范例2:

// C++ code to demonstrate
// the working of oct() function
  
#include 
  
using namespace std;
  
int main()
{
  
    // Initializing the number
    int n = -321;
  
    // Using oct()
    cout << "oct flag: "
         << oct << n << endl;
  
    return 0;
}
输出:
oct flag: 37777777277

参考: http://www.cplusplus.com/reference/ios/oct/

要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”