Why is "sizeof(unsigned int) == sizeof(int)" refused in a cout?

Why can I write: bool a = sizeof(unsigned int) == sizeof(int); cout << "(taille unsigned integer = integer) ? " << a; But this: cout << "(taille unsigned integer = integer) ? " << sizeof(unsigned int) == sizeof(int); produces a compilation error? Invalid operands to binary expression (‘std::basic_ostream<char>::__ostream_type’ (aka ‘basic_ostream<char, std::char_traits<char>>’) and ‘unsigned long’) >Solution… Read More Why is "sizeof(unsigned int) == sizeof(int)" refused in a cout?

iterate char by char through vector of strings

I want to iterate char by char in a vector of strings. In my code I created a nested loop to iterate over the string, but somehow I get an out of range vector. void splitVowFromCons(std::vector<std::string>& userData, std::vector<std::string>& allCons, std::vector<std::string>& allVows){ for ( int q = 0; q < userData.size(); q++){ std::string userDataCheck = userData.at(q);… Read More iterate char by char through vector of strings

Does new int[] return the address of the first element in the array or the address of the entire array?

int *a = new int[16]; How do I access the array afterwards? Does a hold the address of the entire array or just the first element in the array? Basically, I have this code, struct student { string name; int age; }; int num_students = get_number_of_students(); struct student *students = new student[num_students]; Now How do… Read More Does new int[] return the address of the first element in the array or the address of the entire array?

Constexpr class function definition linking error

Function is declared in hpp file like this: class StringProcessor { static constexpr const char* string_process(const char* initial_string, std::size_t string_length, const char* key, std::size_t key_length); }; And defined in cpp like this: constexpr const char* StringProcessor:: string_process(const char* initial_string, std::size_t string_length, const char* key, std::size_t key_length) { … } How do I call it, because… Read More Constexpr class function definition linking error

Why does this variable have different values in different source files?

I have the following code: main.cpp #include "Test.h" int main() { Create(); } Test.h #pragma once #include <iostream> #include "Function.h" class Test { public: Test(); }; extern Test* g_pTest; inline void Create() { g_pTest = new Test; std::cout << "On Test.h: " << std::endl; PrintAddr(); } Test.cpp #include "Test.h" Test* g_pTest = nullptr; Test::Test() {… Read More Why does this variable have different values in different source files?