14 Replies - 1218 Views - Last Post: 01 April 2011 - 09:45 AM Rate Topic: -----

#1 iamadumbchild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 11

reading a file c++

Posted 31 March 2011 - 03:03 AM

i am actually working with a program where i write a class and i have longitude and latitude for a given city

now i have have a certain function that calls for it and i have written the function but i am having some error, well i have two and i don't know how to procedd from there.

so what i was doing was what you would when you a file with one thing in each line and read the file and store it in a vector but noe each lline no longer has just one thing in it.

so here is my complete code i have already tested the class and it runs i know everything other than this read file function which i haven't been able to figure out from two days now and i read two books still i am stuck and wheni run this it tells me fname not initilized.

/*City.h Begins here */

//city.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include<iostream>
#include <exception>
#include <stdexcept>
#include <string>

const double PI= 3.14159265358979;
const double earth_radius= 6371;

class City{
private:
    std::string nm;
    double latitude;
    double longitude;
    
    bool check_latitude(double lati );
    bool check_longitude(double longi);

public:
        // Constructors and Destructor
        // Default constructor, sets latitude and longitude to 0
        City();
        // Constructor, sets height and width to parameters w and h
        // Throws an invalid_argument exception if log or lat are <= 0
        // The exception's string indicates the error condition
        City(std::string nm,double lati, double longi);
    

        // Getters and Setters
        std::string getCityname(){return nm;};
        double getLatitude(){return latitude;}; //inline method
        double getLongitude(){return longitude;}; //inline method
        // The setter methods throw an invalid_argument exception
        // if log or lat are <= 0, the exception's string indicates the
        // error condition
        // Sets latitude to parameter lat
        void setLatitude(double lati);
        // Sets longitude to parameter log
        void setLongitude(double longi);
        // set the city nametion
        void setCityname(std::string nm);
        double distance(const City & c) const;
    friend std::ostream& operator<<(std::ostream& os, const City& c);           
};

//city.h ends here


// city.cpp : Defines the entry point for the console application.
//
/*City.cpp Begins here */
// city.cpp : Defines the entry point for the console application.
//

#include"city.h"
#include<iostream>
#include<cmath>

// constructors
City::City() : nm(""), latitude(0.0), longitude(0.0) {}

City::City(std::string nm,double lati, double longi){
   City::setCityname(nm);
   City::setLatitude(lati);
   City::setLongitude(longi);
}

bool City::check_latitude(double lati)
{/* Range of latitude is [0,90]*/
    return lati >= -90 && lati<=90;
}

bool City::check_longitude(double longi)
{ /* Range of longitude is [0,180]*/
    return longi >=-180 && longi <= 180;
}

//Setters
void City::setLatitude(double lati)
{
   if(!check_latitude(lati)){
     throw std::invalid_argument("latitude value out of bounds");
   }
     
   latitude=lati; 
}

void City::setLongitude(double longi)
{
   if(!check_longitude(longi)){
       throw std::invalid_argument("longitude value out of bounds");
   }
   
   longitude= longi;
}
void City::setCityname(std::string nm)
{
    this->nm = nm;  
}

double City::distance(const City & c) const
{
    double lati1  = this->latitude * (PI / 180);
    double lati2  = c.latitude * (PI/180);
    double longi1 = this->longitude * (PI/180);
    double longi2 = c.longitude * (PI/180);
    
   double dist =  acos( sin(lati1) * sin(lati2) + cos(lati1) * cos(lati2) * cos(longi2-longi1) ) * earth_radius;
   return dist;
} 

std::ostream& operator<<(std::ostream& os, const City& c){
        char lati_direction;
        char longi_direction;

        if (c.latitude < 0){
                lati_direction = 'S';
        }
        else{
                lati_direction = 'N';
        }

        if (c.longitude < 0){
                longi_direction = 'W';
        }
        else{
                longi_direction = 'E';
        }
   os <<c.nm<<" " << c.latitude<< lati_direction << " " << c.longitude<<longi_direction; //
   return os;
}

 

//city.cpp ends here

#include "city.h"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;


void interFace();
string cityData(string);
vector<City> cityFile(ifstream & ist);

int main(){

        interFace();
        


}

void interFace(){

        char option = 'q';
                do{                                             // a do loop that runs the interface program
                                                                // gives the user a set of options to choose from
                                cout << "          =-  assignment 4  -=   " << endl << endl;
                                cout << "Please enter an option: " << endl;
                                cout << "1) Open city data file in a vector" << endl;
                                cout << "2) add city to vector" << endl;
                                cout << "3) Print the list of cities " << endl;
                                cout << "4) Search for a city and print its latitude and longitude" << endl ;
                                cout << "5) Find the distance between two cities " << endl;
                                cout << "6) Find the central, or hub, city from the list of cities   "<< endl << endl;
                                cout << "q) Quit" << endl;

                                                                // prompts the user to intput one of the above options
                                cin >> option;

                if(option != 'q'){
                        if(option == '1'){
                                                                ////////////Open citydata file in a vector////////////
                                cout << cityData(fname);

                                cout << endl << endl;
                        }else if(option == '2'){
                                                                ////////////add city to vector////////////


                                cout << endl << endl;
                        }else if(option == '3'){
                                                                ////////////Print the list of cities////////////


                        }else if(option == '4'){
                                                                ////////////Search for a city and print its latitude and longitude////////////


                        }else if(option == '5'){
                                                                ////////////Find the distance between two cities ////////////


                        }else if(option == '6'){
                                                                ////////////Find the central, or hub, city from the list of cities  ////////////
                        }
                }
        }while(option != 'q');

                                                                //////////// end of interface////////////

        
        cout << endl << endl;
}



// interface
string Data(string)
{
        string fname; 
                cout << "please enter the name of the file: ";
                        cin >> fname;
                ifstream ist(fname.c_str());
        while (!ist){
                cerr << "error opening file " << endl;
                ist.clear();
                cout << "enter the name of the file" << endl;
                        cin >> fname;
                ist.open(fname.c_str());
        }

        return 0;
}

// opens file
vector<City> CityFile(ifstream & ist)
{
        vector <City> vec;
        int cityData;                                                   // CANNOT CONVERT FROM INT TO "CONST CITY &"
        while (ist >> cityData)
        {
                vec.push_back(cityData);
        }

        return vec;
}


//file vector




so what should I do, i am really stuck here

This post has been edited by iamadumbchild: 31 March 2011 - 03:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: reading a file c++

#2 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: reading a file c++

Posted 31 March 2011 - 03:47 AM

Tell us the exact error that you are getting.
Was This Post Helpful? 0
  • +
  • -

#3 iamadumbchild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 11

Re: reading a file c++

Posted 31 March 2011 - 03:52 AM

View Postchinchang, on 31 March 2011 - 03:47 AM, said:

Tell us the exact error that you are getting.

sure i am sorry i am quite new at this so didn't what all details to post.

1>------ Build started: Project: city, Configuration: Debug Win32 ------
1> stdafx.cpp
1>c:\users\avni\documents\visual studio 2010\projects\city\city\stdafx.cpp(41): error C2065: 'fname' : undeclared identifier
1>c:\users\avni\documents\visual studio 2010\projects\city\city\stdafx.cpp(100): error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'int' to 'City &&'
1> with
1> [
1> _Ty=City
1> ]
1> Reason: cannot convert from 'int' to 'City'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Was This Post Helpful? 0
  • +
  • -

#4 iamadumbchild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 11

Re: reading a file c++

Posted 31 March 2011 - 03:59 AM

View Postiamadumbchild, on 31 March 2011 - 03:52 AM, said:

View Postchinchang, on 31 March 2011 - 03:47 AM, said:

Tell us the exact error that you are getting.

sure i am sorry i am quite new at this so didn't what all details to post.

1>------ Build started: Project: city, Configuration: Debug Win32 ------
1> stdafx.cpp
1>c:\users\avni\documents\visual studio 2010\projects\city\city\stdafx.cpp(41): error C2065: 'fname' : undeclared identifier
1>c:\users\avni\documents\visual studio 2010\projects\city\city\stdafx.cpp(100): error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'int' to 'City &&'
1> with
1> [
1> _Ty=City
1> ]
1> Reason: cannot convert from 'int' to 'City'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




i was wondering there is a post about reading text files i just explored it and there the author talks about overloading the class and it much more neater and tied in could some possible explain me what is going on there.
Was This Post Helpful? 0
  • +
  • -

#5 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: reading a file c++

Posted 31 March 2011 - 04:42 AM

In your function interface(), you are using fname which is not declared anywhere in that function.
Was This Post Helpful? 0
  • +
  • -

#6 iamadumbchild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 11

Re: reading a file c++

Posted 31 March 2011 - 04:59 AM

View Postchinchang, on 31 March 2011 - 04:42 AM, said:

In your function interface(), you are using fname which is not declared anywhere in that function.

so here is what was thinking i was thinking using an overload operator and making it something like
std::istream& operator>>(std::istream& input, city& s)
{
std::getline(input, s.name, ','); //read name
input >> s.id; //read id
input.ignore();
input >> s.fees; //read fees
input.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return input;
}


i just don`t know how to do it

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 31 March 2011 - 05:10 AM

Was This Post Helpful? 0
  • +
  • -

#7 iamadumbchild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 11

Re: reading a file c++

Posted 31 March 2011 - 05:10 AM

View Postiamadumbchild, on 31 March 2011 - 04:59 AM, said:

View Postchinchang, on 31 March 2011 - 04:42 AM, said:

In your function interface(), you are using fname which is not declared anywhere in that function.

so here is what was thinking i was thinking using an overload operator and making it something like
std::istream& operator>>(std::istream& input, city& s)
{
std::getline(input, s.name, ','); //read name
input >> s.id; //read id
input.ignore();
input >> s.fees; //read fees
input.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return input;
}

i just don`t know how to do it


it keeps on giving me errors :>
Was This Post Helpful? 0
  • +
  • -

#8 jimblumberg  Icon User is offline

  • member icon


Reputation: 4003
  • View blog
  • Posts: 12,354
  • Joined: 25-December 09

Re: reading a file c++

Posted 31 March 2011 - 06:08 AM

Post your current code along with the complete error messages. Also please post a small sample of your input file.

Jim

This post has been edited by jimblumberg: 31 March 2011 - 06:08 AM

Was This Post Helpful? 0
  • +
  • -

#9 kiasta  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 257
  • Joined: 18-November 07

Re: reading a file c++

Posted 31 March 2011 - 09:26 AM

So, basically you're having trouble reading from a file?

Here, this link should help.

Or I have some old code that might help you:

file.open(filename);
            if (file.fail())                                                                    //Check if the file is there
            {
                if (debug == 1)
                {
                    cout << "\n First decrypt.h file verification check failed.";
                }
                cout << "\n\n Unable to open the file";                                         //If the file is not there, returns 0;
                getch();
                return EXIT_FAILURE;                                                            //Exits function
            }
            else if (file.is_open())
            {
                system("cls");
                cout << "\n Encrypted content:";
                cout << "\n\n\n Line " << line << ": ";
                for (textinc = 0; !file.eof(); ++textinc)
                {
                    file.get(text[textinc]);
                    text[textinc] = text[textinc] - (0xEFAF * (1 + (1/2)));                     //!Decryption
                    if (text[textinc] == '\t')
                    {
                        ++line;
                        text[textinc] = ' ';
                        cout << "\n\n Line " << line << ": ";
                    }
                    else if (text[textinc] == '\r')
                    {
                        ++line;
                        text[textinc] = ' ';
                        cout << "\n\n Line " << line << ": ";
                    }
                    else
                    {
                        cout << text[textinc];
                    }
                }
                file.close();
            }
            return EXIT_SUCCESS;



Don't worry about the encryption/decryption and you may want to use a vector instead of a char array. Like I said it is old code so it might not be the best example, but it might help you to understand.

*EDIT*
Here is another example:
int fileRead(char *filename, int debug)
        {
            ifstream file;
            int linenum = 0;
            string line = " ";
            file.open(filename);
            if (file.fail())
            {
                if (debug == 1)
                {
                    cout << "\n First read.h file verification check failed.";
                }
                cout << "\n\n Unable to open the file";
                getch();
                return EXIT_FAILURE;
            }
            else if (file.is_open())
            {
                system("CLS");
                cout << "\n Decrypted content:";
                cout << "\n\n";
                while (!file.eof())
                {
                    getline(file, line);
                    cout << "\n\n Line " << linenum << ": " << line;
                    ++linenum;
                }
                file.close();
            }
            return EXIT_SUCCESS;
        }



You will probably understand that a little bit better.

This post has been edited by kiasta: 31 March 2011 - 09:32 AM

Was This Post Helpful? -1
  • +
  • -

#10 iamadumbchild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 11

Re: reading a file c++

Posted 31 March 2011 - 11:35 PM

View Postjimblumberg, on 31 March 2011 - 06:08 AM, said:

Post your current code along with the complete error messages. Also please post a small sample of your input file.

Jim


here it is




/*City.h Begins here */

//city.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include<iostream>
#include <exception>
#include <stdexcept>
#include <string>

const double PI= 3.14159265358979;
const double earth_radius= 6371;

class City{
private:
    std::string nm;
    double latitude;
    double longitude;
    
    bool check_latitude(double lati );
    bool check_longitude(double longi);

public:
        // Constructors and Destructor
        // Default constructor, sets latitude and longitude to 0
        City();
        // Constructor, sets height and width to parameters w and h
        // Throws an invalid_argument exception if log or lat are <= 0
        // The exception's string indicates the error condition
        City(std::string nm,double lati, double longi);
    

        // Getters and Setters
        std::string getCityname(){return nm;};
        double getLatitude(){return latitude;}; //inline method
        double getLongitude(){return longitude;}; //inline method
        // The setter methods throw an invalid_argument exception
        // if log or lat are <= 0, the exception's string indicates the
        // error condition
        // Sets latitude to parameter lat
        void setLatitude(double lati);
        // Sets longitude to parameter log
        void setLongitude(double longi);
        // set the city nametion
        void setCityname(std::string nm);
        double distance(const City & c) const;
    friend std::ostream& operator<<(std::ostream& os, const City& c);
};

//city.h ends here


// city.cpp : Defines the entry point for the console application.
//
/*City.cpp Begins here */
// city.cpp : Defines the entry point for the console application.
//

#include"city.h"
#include<iostream>
#include<cmath>
using namespace std;
// constructors
City::City() : nm(""), latitude(0.0), longitude(0.0) {}

City::City(std::string nm,double lati, double longi){
   City::setCityname(nm);
   City::setLatitude(lati);
   City::setLongitude(longi);
}

bool City::check_latitude(double lati)
{/* Range of latitude is [0,90]*/
    return lati >= -90 && lati<=90;
}

bool City::check_longitude(double longi)
{ /* Range of longitude is [0,180]*/
    return longi >=-180 && longi <= 180;
}

//Setters
void City::setLatitude(double lati)
{
   if(!check_latitude(lati)){
     throw std::invalid_argument("latitude value out of bounds");
   }
     
   latitude=lati; 
}

void City::setLongitude(double longi)
{
   if(!check_longitude(longi)){
       throw std::invalid_argument("longitude value out of bounds");
   }
   
   longitude= longi;
}
void City::setCityname(std::string nm)
{
    this->nm = nm;  
}

double City::distance(const City & c) const
{
    double lati1  = this->latitude * (PI / 180);
    double lati2  = c.latitude * (PI/180);
    double longi1 = this->longitude * (PI/180);
    double longi2 = c.longitude * (PI/180);
    
   double dist =  acos( sin(lati1) * sin(lati2) + cos(lati1) * cos(lati2) * cos(longi2-longi1) ) * earth_radius;
   return dist;
} 

std::ostream& operator<<(std::ostream& os, const City& c){
	char lati_direction;
	char longi_direction;

	if (c.latitude < 0){
		lati_direction = 'S';
	}
	else{
		lati_direction = 'N';
	}

	if (c.longitude < 0){
		longi_direction = 'W';
	}
	else{
		longi_direction = 'E';
	}
   os <<c.nm<<" " << c.latitude<< lati_direction << " " << c.longitude<<longi_direction; //
   return os;
}

#include "city.h"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;


void interFace();
string cityData(string);
vector<City> cityFile(ifstream & ist);

int main(){

	interFace();
	


}

void interFace(){

	char option = 'q';
		do{						// a do loop that runs the interface program
								// gives the user a set of options to choose from
				cout << "          =-  assignment 4  -=   " << endl << endl;
				cout << "Please enter an option: " << endl;
				cout << "1) Open city data file in a vector" << endl;
				cout << "2) add city to vector" << endl;
				cout << "3) Print the list of cities " << endl;
				cout << "4) Search for a city and print its latitude and longitude" << endl ;
				cout << "5) Find the distance between two cities " << endl;
				cout << "6) Find the central, or hub, city from the list of cities   "<< endl << endl;
				cout << "q) Quit" << endl;

								// prompts the user to intput one of the above options
				cin >> option;

		if(option != 'q'){
			if(option == '1'){
								////////////Open citydata file in a vector////////////
				cout << cityData(fname);

				cout << endl << endl;
			}else if(option == '2'){
								////////////add city to vector////////////


				cout << endl << endl;
			}else if(option == '3'){
								////////////Print the list of cities////////////


			}else if(option == '4'){
								////////////Search for a city and print its latitude and longitude////////////


			}else if(option == '5'){
								////////////Find the distance between two cities ////////////


			}else if(option == '6'){
								////////////Find the central, or hub, city from the list of cities  ////////////
			}
		}
	}while(option != 'q');

								//////////// end of interface////////////

	
	cout << endl << endl;
}



// interface
string Data(string)
{
	string fname; 
		cout << "please enter the name of the file: ";
			cin >> fname;
		ifstream ist(fname.c_str());
	while (!ist){
		cerr << "error opening file " << endl;
		ist.clear();
		cout << "enter the name of the file" << endl;
			cin >> fname;
		ist.open(fname.c_str());
	}

	return 0;
}

// opens file
vector<City> CityFile(ifstream & ist)
{
	vector <City> vec;
	int cityData;							// CANNOT CONVERT FROM INT TO "CONST CITY &"
	while (ist >> cityData)
	{
		vec.push_back(cityData);
	}

	return vec;
}


//file vector





so there is two major errors with this what i have got here;

i have to make the read file function something like

fstream file("data.txt"); // open file
string line;
while (!file.eof()) {
getline(file, line); // read a line
stringstream ss(line); // a stringstream allows us to extract formatted data easily

string cityName;
double latitude;
double longitude;

string name >> cityName;
double lati >> latitude;
double longi >> longitude;
// our data for each line is in these three variables! Now do something with them.
}



a sample run would be a text file containing follow data
Calgary 51.1 -114.0167
Vancouver 49.1833 -123.167
Winnipeg 49.9 -97.2333
Ottawa 45.3167 -75.6667
Moose_Jaw 50.3333 -105.55
Was This Post Helpful? 0
  • +
  • -

#11 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: reading a file c++

Posted 01 April 2011 - 02:01 AM

Before you post code here try and compile it.

After cleaning up the stuff that you should have done, here are the compile errors left that need attention
DIC.cpp: In function ‘void interFace()’:
DIC.cpp:166: error: ‘fname’ was not declared in this scope
DIC.cpp:166: error: ‘cityData’ was not declared in this scope
DIC.cpp: In function ‘std::vector<City, std::allocator<City> > CityFile(std::ifstream&)’:
DIC.cpp:246: error: no matching function for call to ‘std::vector<City, std::allocator<City> >::push_back(int&)’
/usr/include/c++/4.2.1/bits/stl_vector.h:600: note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = City, _Alloc = std::allocator<City>]


You need to get those sorted before you can move any further forward.
Was This Post Helpful? 0
  • +
  • -

#12 iamadumbchild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 11

Re: reading a file c++

Posted 01 April 2011 - 02:30 AM

View Postjanotte, on 01 April 2011 - 02:01 AM, said:

Before you post code here try and compile it.

After cleaning up the stuff that you should have done, here are the compile errors left that need attention
DIC.cpp: In function ‘void interFace()’:
DIC.cpp:166: error: ‘fname’ was not declared in this scope
DIC.cpp:166: error: ‘cityData’ was not declared in this scope
DIC.cpp: In function ‘std::vector<City, std::allocator<City> > CityFile(std::ifstream&)’:
DIC.cpp:246: error: no matching function for call to ‘std::vector<City, std::allocator<City> >::push_back(int&)’
/usr/include/c++/4.2.1/bits/stl_vector.h:600: note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = City, _Alloc = std::allocator<City>]


You need to get those sorted before you can move any further forward.


yeah, i tried compiling it but the errora are all in read file part and i have to change it so i thought it was kind of pointless to correct something i wasn't going to use :| could you help me change the read file function to something like
fstream file("data.txt"); // open file
string line;
while (!file.eof()) {
getline(file, line); // read a line
stringstream ss(line); // a stringstream allows us to extract formatted data easily

string cityName;
double latitude;
double longitude;

string name >> cityName;
double lati >> latitude;
double longi >> longitude;




but this should be able to read the data into a vector
Was This Post Helpful? 0
  • +
  • -

#13 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: reading a file c++

Posted 01 April 2011 - 02:35 AM

How about you change it to something like that.
Wouldn't that be a better place to start?
Was This Post Helpful? 0
  • +
  • -

#14 iamadumbchild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 11

Re: reading a file c++

Posted 01 April 2011 - 08:02 AM

View Postjanotte, on 01 April 2011 - 02:35 AM, said:

How about you change it to something like that.
Wouldn't that be a better place to start?

yes that definitely would be but i am not sure i have it complete, how can i try using an incomplete thing and then not know what to complete it with
Was This Post Helpful? 0
  • +
  • -

#15 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1327
  • View blog
  • Posts: 4,552
  • Joined: 19-February 09

Re: reading a file c++

Posted 01 April 2011 - 09:45 AM

The City class is quite good but the rest is confusing.
What you want, I think, is a list of cities which you can read from file, print out the list, etc.

The easiest way is to add a list of cities class, with a vector for the list.

class CityList
{
    
    vector<City> citylist; // list of cities

};



You can then add your interface function, and read from file function etc to the class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1