CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2008
    Posts
    2

    Unhappy c++ project problem

    hello everyone out there.
    my first time trying this kind of web site. i need help in my project if anyone can please.

    I need to pull out text line from a file in alphabetical order by the name. example data is saved in a file called sample.txt. i just don't know where to start from. i could have put my own program to show, but i really have no clue where to start from. Please someone help me get it right. thanx

    example:
    Tony | Tacoma | WA | $5,435.00
    Eric | Issaquah | WA | $1,238.00
    John | Beaver Creek | OR | $345.00

    output should be:
    Eric | Issaquah | WA | $1,238.00
    John | Beaver Creek | OR | $345.00
    Tony | Tacoma | WA | $5,435.00

  2. #2
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    Re: c++ project problem

    One possible way of doing it.
    1. Read each line from the file until EOF is encountered.
    2. Store each line in a string buffer.
    3. Sort the buffer.

    Do, you have knowledge of std::string or std::priority_queue?
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

  3. #3
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Lightbulb Re: c++ project problem

    This should get you started.

    Code:
    #include <iostream>
    
    int main()
    {
       std::cout << "Start writing program here!" << std::endl;
       return 0;
    }
    Take a look at these:
    http://www.research.att.com/~bs/bs_faq.html
    http://www.research.att.com/~bs/bs_faq2.html
    http://www.cplusplus.com/reference/iostream/fstream/
    Last edited by kempofighter; May 12th, 2008 at 10:12 AM. Reason: added std::

  4. #4
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    81

    Re: c++ project problem

    Quote Originally Posted by kempofighter
    Code:
    std::cout << "Start writing program here!" << endl;
    The above code won't compile - std:: is missing in front of endl ... i.e. it should be:
    Code:
       std::cout << "Start writing program here!" << std::endl;

  5. #5
    Join Date
    May 2008
    Posts
    2

    Angry Re: c++ project problem

    Thank you mr rohit for your help, but i have no clue how to save a line in a string. if you can please do this huge favor and write this small program, i will b very thankful to u.

  6. #6
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: c++ project problem

    Quote Originally Posted by ali09
    if you can please do this huge favor and write this small program, i will b very thankful to u.
    Read this.

  7. #7
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    Re: c++ project problem

    Quote Originally Posted by ali09
    Thank you mr rohit for your help, but i have no clue how to save a line in a string. if you can please do this huge favor and write this small program, i will b very thankful to u.
    I'm sorry ali09. That would be most unethical. As the saying goes - "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." However, I would be glad to see you at least try something. Post your attempt at a working solution here and I will nudge you in the write direction. I'm here to help but not to spoon-feed.
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured