How i can use bool function and strcmp in structures | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How i can use bool function and strcmp in structures

I want to write program which will check the name. Itry this in following code: https://code.sololearn.com/cA5a5A6a17a1/?ref=app

3rd Mar 2021, 2:46 PM
Adilx01
9 Answers
+ 6
You are defining isTrue() twice instead of having a declaration and a definition, which results in the second one not having a proper declaration. If the second one is the method you want, replace the definition inside the structure by the corresponding declaration: bool isTrue(); You also forgot to include the <cstring> header file for strcmp(), while <iomanip> and <cmath> seem to be redundant.
3rd Mar 2021, 2:56 PM
Shadow
Shadow - avatar
+ 3
1) Include the <string.h> or <cstring> library (they are the same) for "strcmp" function. 2) Remove the "<char> ime" parameter from your method and it will automatically use class' attribute. And the definition of a method/function "Human::imo" outside the "Human" definition is unnecessary: you have already defined it; it is necessary only if you declared and not defined it.
3rd Mar 2021, 3:02 PM
#0009e7 [get]
#0009e7 [get] - avatar
+ 2
Am I the only one not getting the input dialog to come up with `cin.getline`? the code isn't asking for input even after the fix.
3rd Mar 2021, 3:12 PM
Ipang
+ 2
get You edited your last post. The two sentences you talked about wasn't there when I read it. And please, don't give me stuffs that are not in the OP's code cause that is another story.
3rd Mar 2021, 3:34 PM
Ipang
+ 2
get My actual intention was to get the OP to learn and use C++ string in C++ code unless char array was really necessary.
3rd Mar 2021, 3:47 PM
Ipang
+ 1
Ipang, "ostream::std::cin.getline" is used to receive string (raw) input with spaces. It is SoloLearn's issue that it does not ask for input in that case. But you can use some "cin >> {declared_but_unused_variable};", which makes no sense to the program, so that Playground will ask for input.
3rd Mar 2021, 3:15 PM
#0009e7 [get]
#0009e7 [get] - avatar
+ 1
get I know that, but Code Playground doesn't pop the input dialog up where I'm supposedly write a name to test Do you get the input dialog to pop running the OP's code?
3rd Mar 2021, 3:19 PM
Ipang
+ 1
Ipang, I thought that you did not get the point of "cin.getline". 😂
3rd Mar 2021, 3:37 PM
#0009e7 [get]
#0009e7 [get] - avatar
0
Ipang, no. If you did not understand the last two sentences, there is an example: type `string __unused_string__; cin >> __unused_string__` after the "<int> main ()" function for input pop-up to be displayed.
3rd Mar 2021, 3:27 PM
#0009e7 [get]
#0009e7 [get] - avatar