Strings

T

Tim K

ok I want to compare a string based on the input

so lets say I have

string bookType = "";

cout << "Enter type of book:(enter either paperback or hardback):";
getline(cin,bookType);

//what is the best way to do the following:

if bookType = "paperback"
cout << "you chose paperback"
else
cout << "you chose hardback"


Thanks,

Tim
 
U

UmaGrama

You can always use to compare two strings. Make sure to include string.h





ïnt result = strcmp(Str1, Str2);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top