ファイル内の文字列(この場合は名前)を検索するプログラムを開発中です。私はプログラムが大文字と小文字を区別しないようにしたかったのですが、strcmpがあります。私はボットファイルとユーザー入力を小文字に変換することを考えていました。しかし、それは非効率的です。これを克服するための他の提案はありますか?
これはちょうどstrcmpi()を使用せずにstrcmp()を大文字と小文字を区別しないようにする
cout << "\n Enter the Guests name: ";
cin.getline(look_4_person, 256); //name that is being looked up
cout << "\n Searching... \n";
while(!name_file.eof())
{
++place;
name_file.getline(person,255);
if(strcmpi (person,look_4_person)==0)
{
found=place;
}
}
cout << "\n" << look_4_person << " is number " << found <<
" on the list \n";
これはひどいスタイルで、while(!name_file.eof())はバグです。現代のC++を良い本で読むべきです。 –
@BaummitAugen現在、私はBig C++(2nd Edition)を使用しています ご意見はありますか? – Pouya
https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list –