How can I create a integer with 32 bits?
And how can I use scanf and printf with that?
Thanks!
An integer is, by its nature, 32 bits. Note that 4 bytes=32 bits.
Is it a long? or anything?
My doubt is how I can represent it in scanf and printf (like %d for int).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <cstdint>
#include <cinttypes>
#include <cstdio>
#include <iostream>
int main()
{
// http://en.cppreference.com/w/cpp/header/cstdint
std::int32_t a ; // signed integer type, exactly 32 bits (if available)
std::int_fast32_t b ; // fastest available signed integer type, at least 32 bits
std::int_least32_t c ; // smallest available signed integer type, at least 32 bits
// http://en.cppreference.com/w/cpp/header/cinttypes
std::scanf( "%" SCNd32 " %" SCNdFAST32 " %" SCNdLEAST32, &a, &b, &c ) ; // decimal
std::printf( "%" PRId32 " %" PRIdFAST32 " %" PRIdLEAST32 "\n", a, b, c ) ;
std::cin >> a >> b >> c ;
std::cout << a << ' ' << b << ' ' << c << '\n' ;
}
|
Last edited on
scanf is complicated enough to please even the C++ purists!