当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C++ ios manipulators oct()用法及代码示例


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

用法:

ios_base& oct (ios_base& str)

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


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

范例1:

// C++ code to demonstrate 
// the working of oct() function 
  
#include <iostream> 
  
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 <iostream> 
  
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/



相关用法


注:本文由纯净天空筛选整理自guptayashgupta53大神的英文原创作品 ios manipulators oct() function in C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。