reading from a text file help......

This is a discussion on reading from a text file help...... within the C++ Programming forums, part of the General Programming Boards category; hi ppl, i am having trouble linking my text file into a program that im writing. I started with a ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    18

    reading from a text file help......

    hi ppl,

    i am having trouble linking my text file into a program that im writing.

    I started with a basic string to test the outcome of the program which works fine. So,im now testing the program by reading in a sample file.


    the text file is a sequence of letters



    Code:
    int main()
    
     string information; 
      
      information = readFile();  // have a function to read a file in.
    
    
      // HAVING trouble mapping the information from my text file
    
      map<string,int> strSet;
    
    /********************************/
     string data("ATGCATAAAAAAAACATGATGACTAGATGACATACGATCGACTGACTGACTGACTGACTGACGAC");
    
    this is the test string i have been working on.. 
    
    
    /********************************/
    
    
    for( string::iterator it = data.begin(); it != data.end(); ++it )
      for( int i = 1;i <= 4 && i <= distance(it,data.end()); ++i )
        strSet[string(it,i)]++;
    
    
    for( map<string,int>::iterator it2 = strSet.begin(); it2 != strSet.end(); ++it2 ) 
        if (it2->first.size() == 4) 
          cout << it2->second << " - " << it2->first << " matches" << endl;
    sorry if i been unclear...if you have any querys let me know...

    any help would be appreciated as it plays an important part of my work








    [/code]

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    If your file is smaller than the max size of a string, you can read the whole thing into a string and then do your work. Take a look at this recent post.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    18
    Code:
    string data(readFile());
    got it working..thanks pianorain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Reading Character at a time from a text file
    By Giania in forum C Programming
    Replies: 8
    Last Post: 02-25-2006, 02:17 PM
  5. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM

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