3 Replies - 422 Views - Last Post: 11 May 2010 - 05:56 AM Rate Topic: -----

#1 Guest_Sammy H*


Reputation:

maps

Posted 10 May 2010 - 04:09 PM

Hi there, just trying to write the main function of my project. Reading in a list of strings and floats from a text file. Was just wondering whats the best way to get all the information stored in a map? i then have to be able to use prims algorithm on that map later on.

#include<iostream>
#include<map>
#include<cstdlib>
#include<fstream>
#include<string>
using namespace std;

/*Author: Sam Hardman
 *Written:
 *Purpose:
 */

void prims();
void split();
int display(map<string, int>m);

ifstream inStream;
map <string,int>m;

int main()
{
    char getch;
    string Fname;
    string temp = " ";
    int wordIndex = -1;
    
    cout << "please enter the name of the text file" << endl;
    cin >> Fname;
    inStream.open(Fname.c_str());

    if(!inStream){
        cerr << "There is a problem opening your text file" << endl;
        cerr << "Please make sure your file exists" << endl;
        return EXIT_FAILURE;}

    inStream.clear();

    while(!inStream.eof()){
    //read into map.?

    }
    
    display(m);
    inStream.close();

}


This post has been edited by JackOfAllTrades: 10 May 2010 - 04:57 PM
Reason for edit:: Fixed code tags.


Is This A Good Question/Topic? 0

Replies To: maps

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: maps

Posted 10 May 2010 - 09:32 PM

Quote

Reading in a list of strings and floats from a text file

Then why is the map defined like this?
map <string,int>m;


Also, what makes you think that a map is the best for this task? Could you post an example of your file's data?
Was This Post Helpful? 0
  • +
  • -

#3 Guest_sammy H*


Reputation:

Re: maps

Posted 11 May 2010 - 05:47 AM

yeah fixed that up, we have to use a map, cause were learning about maps at the moment.
input data is like this:
Epping,Marsfield,6.5
where Epping and marsfield are a point on a map, and 6.5 is the distance between them.

cheers
Was This Post Helpful? 0

#4 janotte  Icon User is offline

  • code > sword
  • member icon

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

Re: maps

Posted 11 May 2010 - 05:56 AM

Have a read here:
http://www.cplusplus...stl/map/insert/
and here
http://www.cplusplus...erence/stl/map/
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1