Linked Questions
13 questions linked to/from Converting bool to text in C++
2493 votes
10 answers
1.1m views
What are the basic rules and idioms for operator overloading?
Note: The answers were given in a specific order, and have received varying amounts of votes over time. Since the order of answers depends on your answer sorting preferences, here's an index of the ...
657 votes
43 answers
1.5m views
std::string formatting like sprintf
I have to format std::string with sprintf and send it into file stream. How can I do this?
737 votes
8 answers
1.4m views
What is the printf format specifier for bool?
Since ANSI C99 there is _Bool or bool via stdbool.h. But is there also a printf format specifier for bool? I mean something like in that pseudo code: bool x = true; printf("%B\n", x); which would ...
156 votes
9 answers
71k views
Restore the state of std::cout after manipulating it
Suppose I have a code like this: void printHex(std::ostream& x){ x<<std::hex<<123; } .. int main(){ std::cout<<100; // prints 100 base 10 printHex(std::cout); //...
85 votes
5 answers
59k views
Does GCC support C++20 std::format?
If it doesn't, do you know what compiler or version will? See cppreference/format.
7 votes
3 answers
4k views
C++ Boolean function returning 56
I have a function to return a bool: bool restart() { std::string answer; bool answered = false; while(answered == false) { cout << endl << endl << "Do you ...
0 votes
4 answers
3k views
Boolean to String and combining boolalpha with a method instead of having to type it separately when printing
#include <iostream> #include <cmath> #include <string> using namespace std; string STRING; bool isEqual(double a, double b) { return fabs(a-b) ==0; } int ...
1 vote
1 answer
1k views
How do I reverse the effect of "cout << boolalpha" in c++?
bool one = true; bool two = false; bool three = true; bool four = false; cout << boolalpha; cout << "value of one : " << one << endl; cout << "value of ...
0 votes
1 answer
2k views
How can I make my function bring back true or false
I am a newbie at C++ and I got really stuck at this problem: When the user enters 2 numbers EX: 1 and 2 than the code has to figure out if the first number is grater or not from the first one, the ...
0 votes
2 answers
594 views
C++ send output of function to cout
So I have a function called isEmpty() to check if a specified array has been filled with variables. bool isEmpty() const; This is: bool Array::isEmpty() const { if(elemData == NULL) ...
0 votes
1 answer
1k views
C++ isPrime function: How can I return a Boolean value from a function that takes an integer parameter?
I had to create a function that takes an integer parameter called number and the function would check to see if number is a prime number or not. Everything works but the output to the user would be a ...
2 votes
2 answers
421 views
How do I create an expression using macros in C?
I need a macro that takes input as MACRO(x, y, z, ...) and expands to arr[0] == x && arr[1] == y && arr[2] == z ... Any ideas? arr is char[], and macro args are single chars
0 votes
4 answers
121 views
what is the recursive form of this code?
I was trying to locate vector a in vector b. So it's like if vector a is in vector b then return true else false. And vector a should be like {1,2,3} and b should like {4,1,2,3,5,5,7}. The output of ...