Click to See Complete Forum and Search --> : c++ project problem


ali09
May 7th, 2008, 10:56 PM
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

angelorohit
May 8th, 2008, 12:51 AM
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?

kempofighter
May 8th, 2008, 08:36 PM
This should get you started.

#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/

stephendoyle75
May 9th, 2008, 05:43 PM
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:
std::cout << "Start writing program here!" << std::endl;

ali09
May 12th, 2008, 10:27 PM
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.

Plasmator
May 12th, 2008, 10:43 PM
if you can please do this huge favor and write this small program, i will b very thankful to u.Read this (http://www.codeguru.com/forum/showthread.php?t=366302).

angelorohit
May 13th, 2008, 05:18 AM
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.