Finding in CSV

I am writing a code that will find items in a csv file. One way is through finding the name and displaying the lat/long that goes with the location and vica-versa. Find=name shows lat/long Numbers=lat/long shows name

If anyone has any ideas, I would like to hear!

City.h
1
2
3
4
5
6
7
8
9
10
11
  #pragma once
#include <string>
class City
{
public:
	City(std::string words_arg);
	std::string& find();
	std::string& numbers();
private:
	std::string words;
};


City.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "City.h"
#include <string>
#include <iomanip>
#include "stdafx.h"
#include <sstream>

using namespace std;

City::City(std::string words_arg) : words{ words_arg } {}

string& City::find() {//locates city by name
	
}

string& City::numbers() {//locates city by lat/long

}


main.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
// Taylor Lane HW7.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "City.h"
#include <iomanip>
#include <iostream>
#include <string>
#include <fstream>


using namespace std;

int main()
{
	std::fstream file("worldcities.csv", ios::in);
	if (!file.is_open())
	{
		std::cout << "File not found!";
	}
	int option = 0;
	string first;
	string second;
	do {
		cout << "How would you like to search the list?" << endl <<
			"1) Name of location" << endl <<
			"2) Latitude/longitude" << endl <<
			"3) Exit" << endl <<
			"Which option would you like (1-3)?";
		cin >> option;
		if (option < 1 || 3 < option) {
			cout << "Can't understand your answer. Please try again." << endl;
			continue;
		}
		City location();
		if (option == 3) { break; }
		switch (option) {
		case 1:
			cout << "What location are you searching for? ";
			cin >> first;
			cout << endl;
			cout << "Here is your location and ones closest to it! "
			<< endl << endl
			<< location().find();
			break;
		case 2:
			cout << "What location are you searching for? ";
			cin >> second;
			cout << endl;
			cout << "Here is your location and closest to it! " << endl << endl
			<< location().numbers();
			break;
		}
	} while (0 < option || option < 6);

	system("pause");
			return 0;
		}
I am writing a code that will find items in a csv file.

Perhaps you should first write a function that reads the data from your CSV file and stores the results into a container of some sort. Searching a file is a fairly expensive operation while searching memory is much less expensive.

One way is through finding the name and displaying the lat/long that goes with the location and vica-versa. Find=name shows lat/long Numbers=lat/long shows name

Sounds good, I suggest you try this idea out.

Topic archived. No new replies allowed.