VUEKID 0 Light Poster

How would I search within a vector array for a user input? I need to find the city in the vector array and use it's index to compare distances between other arrays with the array. This is what I have so far, I've read the cvs file to a vector array and now i need to search but i'm lost. HELP WOULD BE APPRECIATIVE. Thanks

#pragma warning(disable: 4786) // VC++ 6.0 disable warning about debug line too long
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>    // std::find 
using namespace std;
typedef vector<string> LINE;


int main()
{
    string line;
    int pos;

    vector<LINE> array;

    ifstream in("worldcities.csv");
    if(!in.is_open())
    {
        cout << "Failed to open file" << endl;
        return 1;
    }
    while( getline(in,line) )
    {
        LINE ln;
        while( (pos = line.find(',')) >= 0)
        {
            string field = line.substr(0,pos);
            line = line.substr(pos+1);
            ln.push_back(field);
        }
        ln.push_back(line);
        array.push_back(ln);
    }

    //for (int i = 0; i < array.size (); i++)
    //{    
    //vector <string> cityData = array.at(i);
    //for (int j = 0; j < cityData.size(); j++)    
    //{
    //  cout << cityData.at(j) << ",";
    //}
    //cout << endl;
    //}


    string input;
    do
    {
    cout << "The worldcities.cvs contained infor on 120 cities." << endl;
    cout << "Enter a city by name or number (1-120)" << endl; 
    std::getline (std::cin,input);


    for ( int i=0; i<array.size(); i++) 
    {
        //Need help searching for the above input city or number row where the city is located in the array.

    }


    if(false)
    {
        cout << "I don't understand your input" << endl;
        continue;
    }
    }while (true);

    system("pause");
    return 0;
}
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.