Hello
I have a .csv file about 3 columns and more than 2000 rows (and growing). I need to write a program to get input from user and search the .csv file for that input, display the input and everything on that line.
.csv file example: street names , location , type of controller
1- alta & jones , NW , apogee
2- alta & pecos , SW , next phase
and it goes on and on for 2000 rows.
I need to ask the user which streets he wants to look up, and the program should display the whole line.
example of user input and program output:
user inputs (street names): alta & jones
program output: alta & jones , NW , apogee
This is what I have so far (thanks to cplusplus forum experts) and all this program does is it will print to display everything on the .csv file, Oh and did I mention that I was an absolute beginner.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
string a, b, c, location;
char answer = 'n';
while (answer == 'n' || answer == 'N')
{
cout << " \n give me first street name: ";
cin >> a;
cout << " \n give me second street name: ";
cin >> b;
c = a + " & " + b;
cout << c ;
cout << " \n is that right (y/n) " << endl;
cin >> answer;
if (answer == 'y' || answer == 'y')
{
cout<<" ok " << endl;
}
else
{
cout<<" oh no " << endl;
}
std::string line_;
ifstream file_("cab location1.csv");
if(file_.is_open())
{
while(getline(file_,line_))
{
std::cout<<line_<< '\n';
}
file_.close();
}
else
std::cout<<"file is not open "<< '\n';
std::cin.get();
}
}
| |
Again any help is greatly appreciated.