cstdint

'uint32_t' does not name a type

大兔子大兔子 提交于 2019-12-31 08:15:27
问题 I'm trying to compile a C++ software package that was written in 2007 and I'm getting this error: error: ‘uint32_t’ does not name a type This is happening in 64-bit Ubuntu using g++ 4.5.2. It compiles fine on 64-bit CentOS using g++ 4.1.2. Is there an #include or a compiler flag that I'm missing? Or, should I use typedef to assign uint32_t to a size_t or maybe an unsigned int ? 回答1: You need to include stdint.h #include <stdint.h> 回答2: You need to #include <cstdint> , but that may not always

How to output unsigned/signed char or <cstdint> types as integers with << in C++

独自空忆成欢 提交于 2019-12-08 02:11:48
问题 Background: I have template stream operators (e.g. operator << (ostream &, std::vector <T>) ) (that output container elements that may possibly be of some 8-bit integer type, (e.g. unsigned char , int_least8_t , et cetera). Problem: Default is that these types are output as char (ASCII). I only used char (or wchar_t or whatever) for ASCII variables, never unsigned/signed types. How do I get these other 8-bit types to always be output as signed int / unsigned int (numbers) instead, even when

'uint32_t' does not name a type

隐身守侯 提交于 2019-12-02 17:14:10
I'm trying to compile a C++ software package that was written in 2007 and I'm getting this error: error: ‘uint32_t’ does not name a type This is happening in 64-bit Ubuntu using g++ 4.5.2. It compiles fine on 64-bit CentOS using g++ 4.1.2. Is there an #include or a compiler flag that I'm missing? Or, should I use typedef to assign uint32_t to a size_t or maybe an unsigned int ? You need to include stdint.h #include <stdint.h> plasma You need to #include <cstdint> , but that may not always work. The problem is that some compiler often automatically export names defined in various headers or

Should I use cstdint?

半世苍凉 提交于 2019-11-27 12:02:10
I have been pondering on whether or not I should use the typedefs inside <cstdint> or not. I personally prefer writing uint32_t over unsigned int and int8_t over char etc... since it to me is alot more intuitive. What do you guys think? Is it a good idea to use the typedefs from <cstdint> or not? Are there any disadvantages? Actually, I would suggest using both. If you want something that is definitely 32-bits unsigned, use uint32_t. For example, if you are implementing a "struct" to represent an external object whose specification defines one of its fields as 32 bits unsigned. If you want

Should I use cstdint?

末鹿安然 提交于 2019-11-26 18:08:28
问题 I have been pondering on whether or not I should use the typedefs inside <cstdint> or not. I personally prefer writing uint32_t over unsigned int and int8_t over char etc... since it to me is alot more intuitive. What do you guys think? Is it a good idea to use the typedefs from <cstdint> or not? Are there any disadvantages? 回答1: Actually, I would suggest using both. If you want something that is definitely 32-bits unsigned, use uint32_t. For example, if you are implementing a "struct" to

long long int vs. long int vs. int64_t in C++

左心房为你撑大大i 提交于 2019-11-26 16:01:27
I experienced some odd behavior while using C++ type traits and have narrowed my problem down to this quirky little problem for which I will give a ton of explanation since I do not want to leave anything open for misinterpretation. Say you have a program like so: #include <iostream> #include <cstdint> template <typename T> bool is_int64() { return false; } template <> bool is_int64<int64_t>() { return true; } int main() { std::cout << "int:\t" << is_int64<int>() << std::endl; std::cout << "int64_t:\t" << is_int64<int64_t>() << std::endl; std::cout << "long int:\t" << is_int64<long int>() <<

<cstdint> vs <stdint.h>

我怕爱的太早我们不能终老 提交于 2019-11-26 06:20:36
问题 What is the difference between stdint.h and cstdint ? Both of them are available in MSVC (Visual Studio 2010) and gcc-4.5.1. Also both define the intX_t / uintX_t types (where X is the size in bytes of the type). If the rationale in both headers is the same (portable types), what decisions I must take to decide on one or the other? The stdint.h defines each type without any namespace, the cstdint types lies in the std namespace. Is there any reason to include or to not include the defined

long long int vs. long int vs. int64_t in C++

[亡魂溺海] 提交于 2019-11-26 04:39:55
问题 I experienced some odd behavior while using C++ type traits and have narrowed my problem down to this quirky little problem for which I will give a ton of explanation since I do not want to leave anything open for misinterpretation. Say you have a program like so: #include <iostream> #include <cstdint> template <typename T> bool is_int64() { return false; } template <> bool is_int64<int64_t>() { return true; } int main() { std::cout << \"int:\\t\" << is_int64<int>() << std::endl; std::cout <<