My code isnt counting the number of entries and it isnt prin

My code isn\'t counting the number of entries and it isn\'t printing the desired result. Could you please take a look at it and troubleshoot it:

Header file

//countryInfo.h

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

using std::string;
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cout;
using std::ostream;
using std::istream;


void countryinfo(string input,string output);

Main.cpp

#include \"countryinfo.h\"

int main ()
{
   countryinfo(\"countryInfo-1.txt\", \"outputproject.txt\");
}

Country.cpp

#include \"countryinfo.h\"

void countryinfo(string input, string output)
{
   ifstream in(input);
   ofstream out(output);
  
  
  
  
   string iso;
   string iso3;
   string isonume;
   string fips;
   string country;
   string capital;
   double area;
   string population;
   string continent;
   string tld;
   string currencyc;
   string currencyn;
   string phone;
   string postalformat;
   string postalreg;
   string languages;
   string geonameid;
   string neighbour;
   string equivalent;
   string fipscode;
  
   int cunt=0;
  

   getline (in, iso, \'\\t\'); //read from in, store iso and table
   getline (in, iso3, \'\\t\'); //getline will only use string
   getline (in, isonume, \'\\t\');
   getline (in, fips, \'\\t\');
   getline (in, country, \'\\t\');
   getline (in, capital, \'\\t\');
  
   in >>area;
   in.ignore();
  
   getline (in, population, \'\\t\');
  
   getline (in, continent,\'\\t\');
   getline (in,tld, \'\\t\');
   getline (in, currencyc, \'\\t\');
   getline (in, currencyn, \'\\t\');
   getline(in,phone, \'\\t\');
   getline (in,postalformat,\'\\t\');
   getline (in,postalreg,\'\\t\');
   getline (in, languages, \'\\t\');
   getline (in, geonameid, \'\\t\');
   getline (in,neighbour,\'\\t\');
   getline (in, equivalent, \'\\t\');
   getline (in, fipscode);
  
  
   while ( !in.fail() )
   {
       cunt++;
       cout<<iso<<\" \"<<iso3<<\" \"<<isonume<<\" \"<<fips<<\" \"<<country<<\" \"<<capital<<\" \"<<area<<\" \"<<
       population<<\" \"<<continent<<\" \"<<tld<<\" \"<<currencyc<<\" \"<<currencyn<<\" \"<<phone<<\" \"<<postalformat
       <<\" \"<<postalreg<<\" \"<<languages<<\" \"<<geonameid<<\" \"<<neighbour<<\" \"<<equivalent<<\" \"<<fipscode
       <<\" \"<<endl;
      
   getline( in, iso, \'\\t\'); //read from in, store iso and table
   getline( in, iso3, \'\\t\'); //getline will only use string
   getline (in, isonume, \'\\t\');
   getline (in, fips, \'\\t\');
   getline (in, country, \'\\t\');
   getline (in, capital, \'\\t\');
  
   in >>area;
   in.ignore();
   getline (in, population, \'\\t\');
  
   getline (in, continent,\'\\t\');
   getline (in,tld, \'\\t\');
   getline (in,currencyc, \'\\t\');
   getline (in, currencyn, \'\\t\');
   getline(in,phone, \'\\t\');
   getline (in,postalformat,\'\\t\');
   getline (in,postalreg,\'\\t\');
   getline (in, languages, \'\\t\');
   getline (in, geonameid, \'\\t\');
   getline (in,neighbour,\'\\t\');
   getline (in, equivalent, \'\\t\');
   getline (in, fipscode);
      
   }
   cout<<\"count = \"<<cunt <<endl;
}

for textfile

Go to geonames.org ------------select \"Free Gazetteer Data\"-----select \"Countryinfo.txt\"

  
  
  
  
  
  
  
  
  
  
  
  
  

Solution

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <string.h>

using namespace std;

void countryinfo(string input,string output);

int main (){
countryinfo(\"abc.txt\", \"outputproject.txt\");
return 0;
}

void countryinfo(string input , string output)
{
string iso;
string iso3;
string isonume;
string fips;
string country;
string capital;
double area;
string population;
string continent;
string tld;
string currencyc;
string currencyn;
string phone;
string postalformat;
string postalreg;
string languages;
string geonameid;
string neighbour;
string equivalent;
string fipscode;
  
char fileName[1024] = {\'\\0\'} ;
int i = 0;
for(i = 0 ; i < sizeof(input) ; i++){
fileName[i] = input[i];
}
  
ifstream file(fileName);
  
string line;
string partial;
  
int count = 0;
  
while(getline(file, line)) { // \'\ \' is the default delimiter
istringstream iss(line);
getline (iss, iso, \'\\t\'); //read from in, store iso and table
getline (iss, iso3, \'\\t\'); //getline will only use string
getline (iss, isonume, \'\\t\');
getline (iss, fips, \'\\t\');
getline (iss, country, \'\\t\');
getline (iss, capital, \'\\t\');
  
//iss >>area;
//iss.ignore();
  
getline (iss, population, \'\\t\');
getline (iss, continent,\'\\t\');
getline (iss,tld, \'\\t\');
getline (iss, currencyc, \'\\t\');
getline (iss, currencyn, \'\\t\');
getline (iss,phone, \'\\t\');
getline (iss,postalformat,\'\\t\');
getline (iss,postalreg,\'\\t\');
getline (iss, languages, \'\\t\');
getline (iss, geonameid, \'\\t\');
getline (iss,neighbour,\'\\t\');
getline (iss, equivalent, \'\\t\');
getline (iss, fipscode);

count++;
  
cout<<iso<<\" \"<<iso3<<\" \"<<isonume<<\" \"<<fips<<\" \"<<country<<\" \"<<capital<<\" \"<<area<<\" \"<<
population<<\" \"<<continent<<\" \"<<tld<<\" \"<<currencyc<<\" \"<<currencyn<<\" \"<<phone<<\" \"<<postalformat
<<\" \"<<postalreg<<\" \"<<languages<<\" \"<<geonameid<<\" \"<<neighbour<<\" \"<<equivalent<<\" \"<<fipscode
<<\" \"<<endl;
}
  
cout<<\"count = \"<<count <<endl;
  
}

Input for above program text.txt ################

--------------------------------------------------------------------

5880735   Sogi   Sogi       -14.35417   -170.78361   P   PPL   AS       050               0   8   17   Pacific/Pago_Pago   2010-10-12
5880736   Niuloa Point   Niuloa Point       -14.3   -170.67639   T   CAPE   AS       010               0   50   -9999   Pacific/Pago_Pago   2010-10-12
5880737   Utulei   Utulei   Utulei,   -14.28694   -170.68306   P   PPL   AS       010               683   126   123   Pacific/Pago_Pago   2010-10-12
5880738   Solo Hill   Solo Hill       -14.28333   -170.68361   T   MT   AS       010               0   54   55   Pacific/Pago_Pago   2010-09-05
5880739   Solo Point   Solo Point       -14.25639   -170.58333   T   CAPE   AS       010               0   126   127   Pacific/Pago_Pago   2010-10-12
5880740   Afutele Stream   Afutele Stream       -14.33556   -170.81833   H   STM   AS       050               0   5   1   Pacific/Pago_Pago   2010-10-12
5880741   Tfeu Cove   Tafeu Cove       -14.25694   -170.68944   H   BAY   AS       010               0   209   222   Pacific/Pago_Pago   2010-10-12
5880742   Afu Stream   Afu Stream       -14.30667   -170.68778   H   STM   AS       010               0   3   19   Pacific/Pago_Pago   2010-10-12
5880743   Aganoa   Aganoa       -14.27944   -170.57917   P   PPL   AS       010               0   21   1   Pacific/Pago_Pago   2010-10-12
5880744   Afulei   Afulei       -14.28   -170.62389   P   PPL   AS       010               0   -3   -9999   Pac

Output ###################

---------------------------------------------

880735 Sogi Sogi  -14.35417 -170.78361 6.95331e-310 P PPL AS  050    0 8 17 Pacific/Pago_Pago 2010-10-12                                                            

880736 Niuloa Point Niuloa Point  -14.3 -170.67639 6.95331e-310 T CAPE AS  010    0 50 -9999 Pacific/Pago_Pago 2010-10-12                                           

880737 Utulei Utulei Utulei, -14.28694 -170.68306 6.95331e-310 P PPL AS  010    683 126 123 Pacific/Pago_Pago 2010-10-12                                      

880738 Solo Hill Solo Hill  -14.28333 -170.68361 6.95331e-310 T MT AS  010    0 54 55 Pacific/Pago_Pago 2010-09-05                                                  

880739 Solo Point Solo Point  -14.25639 -170.58333 6.95331e-310 T CAPE AS  010    0 126 127 Pacific/Pago_Pago 2010-10-12                                            

880740 Afutele Stream Afutele Stream  -14.33556 -170.81833 6.95331e-310 H STM AS  050    0 5 1 Pacific/Pago_Pago 2010-10-12                                         

880741 Tfeu Cove Tafeu Cove  -14.25694 -170.68944 6.95331e-310 H BAY AS  010    0 209 222 Pacific/Pago_Pago 2010-10-12                                             

880742 Afu Stream Afu Stream  -14.30667 -170.68778 6.95331e-310 H STM AS  010    0 3 19 Pacific/Pago_Pago 2010-10-12                                                

880743 Aganoa Aganoa  -14.27944 -170.57917 6.95331e-310 P PPL AS  010    0 21 1 Pacific/Pago_Pago 2010-10-12                                                        

880744 Afulei Afulei  -14.28 -170.62389 6.95331e-310 P PPL AS  010    0 -3 -9999 Pac 2010-10-12                                                                     

count = 10

My code isn\'t counting the number of entries and it isn\'t printing the desired result. Could you please take a look at it and troubleshoot it: Header file //c
My code isn\'t counting the number of entries and it isn\'t printing the desired result. Could you please take a look at it and troubleshoot it: Header file //c
My code isn\'t counting the number of entries and it isn\'t printing the desired result. Could you please take a look at it and troubleshoot it: Header file //c
My code isn\'t counting the number of entries and it isn\'t printing the desired result. Could you please take a look at it and troubleshoot it: Header file //c
My code isn\'t counting the number of entries and it isn\'t printing the desired result. Could you please take a look at it and troubleshoot it: Header file //c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site