How could I apply input >> ws into my program?
The program works perfect but I wanted it to display like this EX:
Jake Miller,712-9881
How could I go about this?
Thanks for the help guys!
/*
Abstract: This program starts with reading input file which holds people’s names and phone numbers and then save this input data to array.
The program should ask the user to enter a name or partial name to search for.
Any entries in the array that match the string entered should be displayed.
*/
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
string name1;
int x = 0;
constint SIZE = 48;
string data[SIZE];
string searchN;
string arr(string);
//Only part that is missing is input >> ws;
//how to apply that in my situation?
int main()
{
ifstream input;
input.open("clientInfo.txt");
while(!input.eof()){
getline(input,data[x]);
x++;
}
arr(searchN);
input.close();
return 0;
}
string arr(string searchN){
int dataFound = 0;
cout << "Enter a name you would like to search for: ";
getline(cin,searchN);
cout << "Results of your search:" << endl;
for(int i = 0; i < x; i++){
if(data[i].find(searchN.data(), 0) < data[i].length()){
dataFound++;
cout << data[i] << endl;
}
}
if(dataFound == 0){
cout << "Data entered not found";
}
return searchN;
}
The structure of the output of this program looks like this right now:
Enter a name you would like to search for: Li
Results of your search:
Li Chen 555-1212
Process returned 0 (0x0) execution time : 3.126 s
Press any key to continue.
The txt structure looks like this:
Alejandra Cruz 555-1223
Joe Looney 555-0097
Geri Palmer 555-8787
Li Chen 555-1212
Holly Gaddis 555-8878
Sam Wiggins 555-0998
Bob Kain 555-8712
Tim Haynes 555-7676
Warren Gaddis 555-9037
Jean James 555-4939
Ron Palmer 555-2783
Either you search the string for the second blank space or perhaps the first number, or the number is always 8 characters, and insert a comma with a space. Only you know which is the better alternative, assuming they are the only possibilities.
Check out the string functions
http://www.cplusplus.com/reference/string/string/
I thought about taking that route of insert BUT the issue with the code above is it has to come from the txt file.
It's not magic, and unless I misunderstand you, there is only one way to change the string, and that is by one of the various alternatives before or after the data string goes to or from the text file respectively.