Thread: file reading line by line

  1. #1
    Jerry & Tom
    Guest

    file reading line by line

    i have to read from the file all the data before ' : ' and then omit the current and go to the next line and read the data.
    e.g.

    Numbers:
    1, 2, 3;
    Font:
    6, 7, 8;



    and i have got the first 2 lines and no luck with the last 2.


    File.getline(temp,200,':');

    strcpy(temp2,"Numbers");
    if (strcmp(temp,temp2)==0)
    {
    File.getline(temp,200,';');
    int i=0;
    char* token;
    int buffer[200];
    token = strtok( temp, ",;");
    while( token != NULL )
    {
    buffer[i]=i;
    token = strtok( NULL, ",;");
    i++;
    }

    alphabets= new int[i];

    for(int j=0;j<i;j++)
    {
    alphabets[j]=buffer[j];
    }

    numAlphabets=i;
    }

    strcpy(temp2,"Font");
    if (strcmp(temp,temp2)==0)
    {
    File.getline(temp,200,';');
    int i=0;
    char* token;
    char buffer[200];
    token = strtok( temp, ",;");
    while( token != NULL )
    {
    buffer[i]=i;
    token = strtok( NULL, ",;");
    i++;
    }
    states= new int[i];
    for(int j=0;j<i;j++)
    {
    states[j]=buffer[j];
    }
    numStates=i;
    }

  2. #2
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287
    Code:
    #include <vector>
    #include <string>
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    
    
    int main()
    {
    	string findThis;
        string one;
    	string item;
    	vector<string> v;
    	int iii;
    
    	ifstream in("file.txt"); 
    
    	while(!in.eof())
    	{
    
    		getline(in, item);
    		iii = item.find(":");
    		item.erase(iii, item.size() - iii);
    		one = one + item + "\n";
    		
    	}
    
    	cout << one << endl; // this should cout out all of the lines 
    	                     // ending before the :
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. reading words line by line from a file
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 05-04-2008, 12:34 AM
  3. Reading random line from a text file
    By helloamuro in forum C Programming
    Replies: 24
    Last Post: 05-03-2008, 10:57 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM