I need help to store my data i read from a cvs file, how do i input it into my arrays and use it to manipulate in other

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <stdio.h>
#include <fstream>

using namespace std;
const int MAX_ARRAY_SIZE = 120;
void getData (string city[], string country[]), double lat[], double lon[];


int main()
{


string city[MAX_ARRAY_SIZE];
string country[MAX_ARRAY_SIZE];
double lat[MAX_ARRAY_SIZE];
double lon[MAX_ARRAY_SIZE];

    ifstream inFile; //input file stream variable
    inFile.open("worldcities.cvs"); //opens the input file


        for (int index = 0; index < MAX_ARRAY_SIZE; index ++)
        {

         // how to send data to each array to be used in another function?
        }


        inFile.close();

This:

void getData (string city[], string country[]), double lat[], double lon[];

Is not valid C++ for a function prototype.

It's hard to say, since you don't give an example of the data contained in the file.. Is this possible to supply?

I have a file with the content of city, country, and their latitude and longitude ex in separate tabs in a row:

Rome, Italy, 1.3334, 5.6677

I need to read the cvs file and put those information from the row into a array?

Then i need to manipulate the data based on the input user's decisions on entering the name of the city or the line number row it is associated with they want to see the latitude or longitude for ex: if they enter a #1, the program will "cout" line 1 from the cvs file with name,country, latitude, and longitude.

Edited 3 Years Ago by VUEKID

Unless there is some really good reason to use arrays, why not use std::vector constructs that contain structures with your data?

struct location {
    string city;
    string country;
    double latitude;
    double longitude;
};

void getLocationData(vector<location>& locations, ifstream& inFile );

Ok that wOrks, but how would I tackle the part where if a user enter a specific cItY name or liIke a row # where thE city is located in the CVs file to manipulate The data?

Write and test a C++ program to perform the following:
 Read the contents of the .csv file containing city names, latitudes, and longitudes into a set of parallel arrays.
 Repeat the following until the user enters “Quit”.
o Ask the user to pick a city, by name, from the list.

Since you've read the data into an array, you would need to therefore search through the array, over the actua file..

So like a for loop to read the struct array ? How would I specficilly search for the city the user input?

This article has been dead for over six months. Start a new discussion instead.