简体   繁体   中英

setbase(8) and std::cout<<std::oct

Whats the difference between std::cout<<std::setbase(8)<<32; and std::cout<<std::oct<<32; Are they equivalent?

And also, what is the purpose of std::cout.oct ??

std::oct Sets the basefield format flag for the str stream to oct.

std::setbase Sets the basefield format flag to one of its possible values: hex, dec or oct depending on the value of the base parameter.

I think the big difference is that setbase takes an argument so you could pass it a variable containing the numerical base you want. Instead of having a bunch of if statements to check the variable and use dec, oct or hex.

I'm not sure about std::cout.oct though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM