# 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?

# Calculate amount of coins C++

I have the assignment from ZyLab Given six values representing counts of silver dollars, half dollars, quarters, dimes, nickels, and pennies, output the total amount as dollars and cents. The variable totalAmount is used to represent the total amount of money. Output each floating-point value with two digits after the decimal point, which can be… Read More Calculate amount of coins C++

# Function that worked before has stopped working

Essentially, the code is meant to validate, find the manufacture origin, and manufacture date of a vehicle using the VIN number. I had written the "valid" function first and after it worked I moved onto the "origin" and "year" functions. Once they worked, I tested everything together and suddenly the "valid" function would return a… Read More Function that worked before has stopped working

# How do I write this line of code in a more readable manner?

Problem: " Write a C++ program to create a new string of the characters at indexes 0,1, 4,5, 8,9 … from a given string. " Solution (not mine): #include <iostream> using namespace std; string test(string str1) { string result = ""; for (int i = 0; i < str1.length(); i += 4) { int c… Read More How do I write this line of code in a more readable manner?

# 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

# How to change textout() when it's already drawn?

I’m trying to move static TCHAR greeting[] = _T("123"); by using arrows, but it doesn’t move at all. MessageBox is used as a confirmation of getting keyboard input. void move(HWND hWnd, WPARAM wParam, LPARAM lParam, unsigned int *x, unsigned int * y) { RECT rt; if (wParam == VK_LEFT) { GetClientRect(hWnd, &rt); x = x… Read More How to change textout() when it's already drawn?

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

int *a = new int; 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

# How to keep good code practices in a specific case (c++)

So, basically, i have a struct, let’s say struct someStruct {int A; int B;};, and a class. For my specific situation, A must be able to be changed from any scope, but B should only be changed from inside the class. I have no idea of what I’m supposed to do here. I have thought… Read More How to keep good code practices in a specific case (c++)

# 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?