- 1

Hello, please how to display overall bool value of bool array?

https://code.sololearn.com/cj3j7CbrZv22/?ref=app

8th Feb 2022, 8:18 AM
TeaserCode
11 Respuestas
+ 2
TeaserCode, I'm not understanding the question, nor what the code was doing. Please elaborate further in the thread Description, what purpose of the code, and some examples of inputs (if any), and respective outputs.
8th Feb 2022, 8:49 AM
Ipang
+ 1
TeaserCode, This snippet checks whether all of elements of an array were true #include <iostream> #include <algorithm> // std::all_of() int main() { bool one[] { true, false, true, false }; bool two[] { true, true, true, true }; bool three[] { false, false, false, false }; for( auto array : { one, two, three } ) // for each item in { one, two, three } { std::cout << std::boolalpha << std::all_of( array, array + 4, []( const bool v ) { return v; } ); std::cout << '\n'; // std::all_of() returns boolean true when the 1st // argument has all its elements pass the check // by the predicate (lambda in 3rd argument). // 4 represents number of elements to check // `return v;` means to check all elements were true // return !v; means to check all elements were false // https://en.cppreference.com/w/cpp/algorithm/all_any_none_of } return 0; }
8th Feb 2022, 4:27 PM
Ipang
0
OP may mean trying to print bool values as "false or true" Instead of 0 or 1 ..? If yes, then set flag as 'boolalpha' for output format.. cout<<boolalpha<<false;
8th Feb 2022, 9:46 AM
Jayakrishna 🇮🇳
0
Purrose of the code I think is very clear. String b is substring of string a. I would like to display true or false (1 0). I compare each elements of substring with correspending part of a. Then declare bool array to write in each comparision and bool yes for overall displaying. If strings are not the same in one comparision than yes print false (not equal) or true if strings are equal.
8th Feb 2022, 10:02 AM
TeaserCode
0
string a "hallo" string b "allo" Do you mean to have these in the bool array? false true true true true And that overall be false because the 1st element is false (not all elements were true)
8th Feb 2022, 11:07 AM
Ipang
0
Here is question about original string tail. b is ending. So you compare last substring letters between these two strings. And if they are equal then result shall be true, else false. I do this my way. Think about it once again please.
8th Feb 2022, 11:42 AM
TeaserCode
0
Does this line provide the expected output? std::cout << std::boolalpha << ( a.substr( a.size() - b.size() ).compare( b ) == 0 );
8th Feb 2022, 11:53 AM
Ipang
0
Now question is clear but what is your expected output? It's working as per description. May you need only single true or false? If yes, then just use @ipang code..
8th Feb 2022, 11:57 AM
Jayakrishna 🇮🇳
0
Ipang this code you copied from somewhere.
8th Feb 2022, 1:15 PM
TeaserCode
0
TeaserCode, No wrote it myself ...
8th Feb 2022, 1:23 PM
Ipang
0
Do you not know how to print overall bool value from bool array?
8th Feb 2022, 1:34 PM
TeaserCode