954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Read a text file & store it in a Data Structure

Hi :)

How do you write a program that reads a text file (music.txt) & stores it in a Data Structure.

I hope that I explained this well but here is a little more info incase not
Write a program that reads the data from the
music.txt file and store it in a data structure. To implement this data structure you must use an array of songs and each song must be represented by a struct with appropriate fields.

So far all I have is this(very simple I know) but so far is it correct?

Any advice on how to do this would be extremely helpful :)

#include <iostream>
#include <fstream>
#include <strstream>

using namespace std;

int main()
{
	ifstream fin("music.txt");


	if (fin.fail()) {
		cout << "Can't open file!\n";
	}
gretty
Junior Poster
158 posts since Apr 2009
Reputation Points: 10
Solved Threads: 7
 

The first thing you have to do is design the structure. What information is on each line of the file? You can't do anything else until you figure that out.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You