home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,710 of 33,346   
   mariogreece@googlemail.com to All   
   Help reading a file and picking out nume   
   06 Dec 12 11:16:30   
   
   Hello everyone,   
      
   So what i'm trying to do is read a file which contains both characters and   
   numbers   
   I'm kinda new to c++ so bear with me a little bit :P   
   So i cast the lines into strings with getline and then try and convert that   
   with sscanf . In order to do that though i must make a distinction between   
   lines. lines starting with f are for inteer values whereas those starting with   
   v are for floating.  The    
   code seems stuck once i try to run it somewhere and i can't figure out where.   
   I'll include both a sample of the file and my code. any feedback is much   
   appreciated!   
      
   Code:   
   ===================================   
      
   #include    
   #include    
   #include    
   #include    
   #include    
   using namespace std;   
      
   int main ()   
   {	   
   	ifstream myobject("Model_1.txt");   
   	string line;										   
   	if(!myobject.good()) {   
   		cout << " Problem reading Object file! Aborting. ";   
   	}   
   	int number_of_lines = 0,counter,i;   
      	while ( getline(myobject, line) ){   
         	++number_of_lines;   
      	}   
   	myobject.close();   
      	myobject.open("Model_1.txt");   
      	cout << 1 <[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca