/Why i can't match the input with the constant string array?
It always shows the record with -1
Thank you.
/

#include<iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <string>
#include <windows.h>
#include <cmath>
string stuname[3]={"Chan Tai Man, Peter","Ng Fat Tat", "Tsang Chi Wai"};

void searchStudent(){
    string search;
    int record=-1;
    cout<<"Enter Student ID or Student Name: ";
    cin>> search;
    for(int i=0; i<3; i++)
    {
        if(search==stuname[i])
            record=i;
    }
    cout<< record <<endl;   

}
int main(){
 searchStudent();
 return 0;
 }

Print out search and you'll see what the problem is. ;)

so i need to use getline(cin, search) ?
if i use this, something errors will come out in my original prog.

What errors are those?

if i use this, something errors will come out in my original prog.

Post the errors and your updated code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.