سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top