Im trying to write a simple program that will read in a list of names and allow you to search through them. Im having a problem with my cin.getline and my strstr. Im new to c++ and im have a hard time getting my head around c string and its functions. The error I get from the cin.getline is cannot convert parameter 1 from 'std::ifstream' to 'char *' and cannot convert parameter 1 from 'char' to 'char *'
The error I get from the strstr is error C2665: 'strstr' : none of the 2 overloads could convert all the argument types
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
const int SIZE = 50;
int size = 0;
// Array of product descriptions
char phoneDirectory[SIZE];
char name; // For user input
char *strPtr = NULL; // Result from strstr
ifstream inFile;
inFile.open("phonebook");
while (!inFile.fail())
{
cin.getline(inFile,phoneDirectory[size]);
size++;
}
inFile.close();
// Get user input
cout << "Enter a name to search for: ";
cin.getline(name, SIZE);
// Search for the string
int index = 0;
while(index < size)
{
strPtr = strstr(phoneDirectory[index], name);
if (strPtr != NULL)
break;
index++;
}
// Output the result of the search
if (strPtr == NULL)
cout << "No matching names were found.\n";
else
cout << phoneDirectory[index] << endl;
return 0;
}
I cant seem to fix the cin.getline's and the strstr.