c++ - how to search for a string between 4 strings -
i want write program gets 4 strings user , asks user type string see if string exist in 1 of 4 strings have been entered.could please correct mistakes.thank you.(i use dev c++)
#include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; int main() { int x,y,i; string z[40],a; (int i=0;i<4;i++) { cout<<"type 4 strings"; cin>>z[i]; } cout<<"type string search "; cin>>a; (int i=0;i<4;i++) { if(strcmp(z[i],a)==0) cout<<z[i]; else cout<<"error"; } getch (); return 0; }
you can't mix c style string functions (strcmp
) c++ std::string
- works fine compare c++ std::string
types regular if (str1 == str2) ...
, there no need use strcmp
here.
Comments
Post a Comment