So I have question regarding a program I need to write.

I need to read a text file which consists of a location and the coordinates of it's longitude and latitude. The program should be able to read any amount of spaces and tabs in between the tokens. So it could be something like this:

location latitude longitude
location [tab] latitude [tab] longitude

My problem is that I'm a bit fuzzy on how to extract the location into an class array. I know I'm supposed to use the getline function but I'm having trouble figuring out how to make it place it into the class array and skip over the tabs and spaces. I have code... but it's still in the very early stages. Problem is I can't really continue unless I manage to get this part. I have a feeling that I will be able to write the whole thing once I manage to get this part down.

The main.cpp

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

#include "greatCircle.h"
using namespace std;

int main (int argc, char*argv[])
    ifstream fin;
    ofstream fout;
    Place destination;
    int i=0;
    //Open file specified on command line. (argv[1]);
    //If it cannot open the file exit the program.
    if (
       cout <<"Could not open the input file. \n";
    //Open file specified on command line. (argv[2]);
    //If it cannot open the file exit the program.
    if (
       cout <<"Could not open the output file. \n";
    //Initialized to " " as a way of checking which indexes is being 
    destination.location [array_size] = " ";
    /*Initialized to 10000 because no longitude or latitiude can reach
    that high. It is used the same way as above, to check which 
    indexes is used*/
    destination.longitude [array_size] = {10000.0};
    destination.latitude [array_size] = {10000.0};
    while (! fin.eof())
       getline (fin, destination.location[i],' '); 
       getline (fin, destination.latitude[i],' ');
       getline (fin, destination.longitude[i],'\n');  
    return 0;

The header file.

#include <iostream>
#include <string>

using namespace std;

const int array_size = 30;
class Place
             void sort ();
             int min_number;
             void swap();
             double great_circle();
             void convertdg_rd();
             string location [array_size];
             double longitude [array_size];
             double latitude [array_size]; 

I know that this most likely have tons and tons of errors on it already but it's my first time using classes, seperate compliation and I/O streams. At the moment I'm getting "expected primary-expression before '{' token" and "no matching function for call to `getline(std::ifstream&, double&, char)'" errors. Thanks for the help.

1. get rid of the curly braces on lines 38 and 39.
2. your 2nd and 3rd calls to getline() won't work, because you're trying to pass a double in the second parameter, and getline() expects a streamsize (int) variable here. But I don't think you want a getline() here anyway. Probably you want more like a:

fin >> destination.latitude[i];

There may be other errors, but these jumped out at me first.

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