+ 2

What's the problem with this piece of code ?? plz explain??

#include <iostream> using namespace std; int main() { string gender; string rel; cin>>gender; if(gender=="male"){rel ="son"<<endl;} if(gender=="female") {rel ="daughter"<<endl;} cout<<rel<<endl; return 0;}

10th Feb 2018, 8:44 AM
FullCoder ALCHEMIST
FullCoder ALCHEMIST - avatar
7 Antworten
+ 14
Just use, rel ="son"; rel="daughter"; You can't use the endl there. Instead, if you still want it, do rel="son\n";
10th Feb 2018, 9:05 AM
Dev
Dev - avatar
+ 3
@Deekshant the string library support strings that will be used but for other data types you are good to go
11th Feb 2018, 5:30 PM
Raz
Raz - avatar
+ 2
Include string library #include <string>
10th Feb 2018, 9:04 AM
Raz
Raz - avatar
+ 2
thnx for the answers. But why endl wont work here ???? i mean im just ending the line... #confused
10th Feb 2018, 9:10 AM
FullCoder ALCHEMIST
FullCoder ALCHEMIST - avatar
+ 1
@neicore what if i wanted use both string and other variables like int ????
10th Feb 2018, 9:06 AM
FullCoder ALCHEMIST
FullCoder ALCHEMIST - avatar
+ 1
<<endl won't work there
10th Feb 2018, 9:08 AM
Bhavya Sharma
Bhavya Sharma - avatar