+ 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;}
6 odpowiedzi
+ 14
Just use,
rel ="son";
rel="daughter";
You can't use the endl there. Instead, if you still want it, do rel="son\n";
+ 3
@Deekshant the string library support strings that will be used but for other data types you are good to go
+ 2
Include string library
#include <string>
+ 2
thnx for the answers.
But why endl wont work here ????
i mean im just ending the line...
#confused
+ 1
@neicore what if i wanted use both string and other variables like int ????
+ 1
<<endl won't work there