Reading in a txt file with location data

Im trying to figure out how to read in ONLY the (latitude, longitude) coordinate portion of this txt file of size unkown:

1
2
3
4
5
6
7
8
9
10
11
12
13
[user]	[check-in time]		[latitude]	[longitude]	[location id]
58186   2008-12-03T21:09:14Z    39.633321       -105.317215     ee8b88dea22411
58186   2008-11-30T22:30:12Z    39.633321       -105.317215     ee8b88dea22411
58186   2008-11-28T17:55:04Z    -13.158333      -72.531389      e6e86be2a22411
58186   2008-11-26T17:08:25Z    39.633321       -105.317215     ee8b88dea22411
58187   2008-08-14T21:23:55Z    41.257924       -95.938081      4c2af967eb5df8
58187   2008-08-14T07:09:38Z    41.257924       -95.938081      4c2af967eb5df8
58187   2008-08-14T07:08:59Z    41.295474       -95.999814      f3bb9560a2532e
58187   2008-08-14T06:54:21Z    41.295474       -95.999814      f3bb9560a2532e
58188   2010-04-06T06:45:19Z    46.521389       14.854444       ddaa40aaa22411
58188   2008-12-30T15:30:08Z    46.522621       14.849618       58e12bc0d67e11
58189   2009-04-08T07:36:46Z    46.554722       15.646667       ddaf9c4ea22411
58190   2009-04-08T07:01:28Z    46.421389       15.869722       dd793f96a22411



into a data structure that will be able to compare against 4 other set coordinates that I have (a box).
Upper-Left (-124.626080,48.987386)
Upper-Right (-62.361014,48.987386)
Lower-Left (-124.626080,18.005611)
Lower-Right ( -62.361014,18.005611)


I will then need to count the number of coordinates are inside the box. Please advise in any way you can!


closed account (SECMoG1T)
This is crude one btw it can work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 //let's use a simple struct to hold your data
  struct location_data
    {
      double latitude; 
      double longitude; 
    }

///let's say your file is called loc.txt

  ifstream in ("loc.txt");

  if (! in)
    {
       cout <<"couldn't open your file"; exit (1);
    }

 stringstream ss;
 string temp, discard; 
 location_data local; 

  while (in)
    {
      ss.str (""); ss.clear (); /// clear stream before using
    
      getline (in, temp,'\n');
      ss <<temp;

     ss>> discard>> discard;  /// discard the first two values
     ss>> local.latitude>> local.longitude;  // thr rest will be discarded by clear
     ///use object local variables to compare to your reference
      /// this can only work if the format of you loc.txt remains the same
    }
 
 


Good luck
Last edited on
@andy1992 you are awesome. Thanks so much !
Topic archived. No new replies allowed.