another string parsing problem

This is a discussion on another string parsing problem within the C++ Programming forums, part of the General Programming Boards category; ok, here is the deal: I have a txt file, as below: Code: a b c d e f a.o: ...

  1. #1
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572

    another string parsing problem

    ok, here is the deal: I have a txt file, as below:
    Code:
    a
    b
    c
    d
    e
    f
    a.o: a b
    b.o: b c d
    e.o: e f
    something: a.o b.o e.o
    and I have to parse through it, and seperate it omitting the ':' and keeping track of some extra stuff. For example a through f, are basic files, but a.o, b.o, e.o, and somehting are targets, and I need to know that.

    anyways, the first thing I had to do is count all the basic files and targets, and then read them into a map, that was relatively simple:
    Code:
    void ReadFile::readIntoMap( MyMap &mapName, string fileName )
    {
    	ifstream inStream3;	
    	inStream3.open( fileName.c_str() ); //open user chosen file
    
    	//declaring variables
    	int i=0;	//counter
    	int vertex=0;  //place for all the vertices
    	string temp;	//temp place holder
    
    	/*********************************
    	TESTING
    	********************************/
    	cout << endl << "these are the veritces/values in the map: " << endl;
    
    	while( !inStream3.eof() && inStream3.good() )
    	{
    		getline( inStream3, temp );
    		if( temp.length() == 1 )
    			mapName.insert( temp, vertex );
    		else{
    			i=temp.find( ':', 0 );
    			if ( i>0 )
    				temp.resize( i, ' ' );
    			else{
    				i = temp.find( ' ', 0 );
    				temp.resize( i, ' ' );
    			}
    			mapName.insert( temp, vertex );
    		}
    		vertex++;
    		if( vertex > lines )
    			break;
    	}		
    
    	inStream3.close();
    }
    but now I can not just "chop" off the temp (temp.resize( i, ' ' );) because I need the "stuff" that follows it...any ideas?

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Use substr()
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    lol...yeah I actually just used it...I'm close to figuring it out

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    ok, can you guys look at this dumb problem, fscking vc++ spits these errors out...maybe I'm just too tired.... the worst thing is, that it was working fine a fe wminutes ago.
    Code:
    #include <iostream>
    #include <string>
    #include <map>
    using namespace std;
    
    #include "llist.h"
    #include "readfile.h"
    #include "mymap.h"
    //#include "readfile.cpp"
    
    int main()
    {
    	ReadFile read;
    	string temp = "test.txt";
    	read.openFileCountElements( temp );
    
    	cout << read.lines  << endl;
    
    	MyMap one;
    
    	read.readIntoMap( one, temp );
    
    	MyList *mainArray;
    	mainArray = new MyList[read.lines];
    
    	MyList adjList;
    	read.readIntoList( one, temp, mainArray, adjList );
    
    	return 0;
    }
    Code:
    \main.cpp(12) : error C2601: 'main' : local function definitions are illegal
    \main.cpp(33) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.
    Last edited by axon; 04-04-2004 at 11:57 PM.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    why is readfile.cpp commented off?

  6. #6
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    so that you would ask :P

    actually its not supposed to be there...thats not the problem

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  7. #7
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    all behold...I started a new project...copied the files EXACTLY as they were before....and it worked

    ...........................

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  8. #8
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    that was the FIRST thing i told u to do :P

    Kids.

  9. #9
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    yeah but it didn't work the first time....

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  10. #10
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I'm the man just accept it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ string problem
    By gatewalker in forum C++ Programming
    Replies: 6
    Last Post: 06-07-2009, 10:40 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. C/C++ String Problem.
    By Jaken Veina in forum C++ Programming
    Replies: 7
    Last Post: 07-09-2005, 10:11 PM
  4. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21