Input file into array / removing from array / Cstring

Sorry for the big question. I am trying to input a file with a delimiter of | into an array and I was supposed to use cstring instead of string. The file goes in in the order of title|artist|duration|album|.

1. Am I entering into the array correctly? IF so, them am I removing from the array incorrectly? When I try to remove a file, I tell it to remove a certain title and it should remove the whole line when I show again, but it shows everything else that was behind that title. However the output file line gone expect for the delimiters ('|') it had.
2. How do I change it to cstring from string? The getline does not work when I use cstring.

Below is what I had before. And I'll post the whole code in a different comment if needed (its long). Thank you for any advice.

Imputing File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  int loadFile(string pathName)
{
	int i = 0;
	int count = 0;

	ifstream inFile;

	
	inFile.open("songs.txt");

        // Open File Error
	if (!inFile)
	{
		return -1;
	}

	else if (inFile)
	{
		for (i = 0; !inFile.eof() && i < ARRAY_SIZE; i++)
		{
			getline(inFile, song[count].title, '\|');
			getline(inFile, song[count].artist, '\|');
			getline(inFile, song[count].duration, '\|');
			getline(inFile, song[count].album, '\|');
			count++;
		}

		// Spits out record counts
		cout << i << " record(s) loaded successfully. " << endl;
		cout << " " << endl;
		return i;
	}

	inFile.close();
	inFile.clear(std::ios_base::goodbit);



	return 0;
}


Removing line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void removeSong(int count, string title, string album)
{

//	ofstream outputFile;

//	cin.ignore();
//	cout << "Please enter the song title to remove: " << endl;
//	getline(cin, title, '\n');


//	outputFile.open("songs.txt", ios::out | ios::trunc);

//	int b = 0;

//	for (int i = 0; i < count; i++)
//	{
//		if (song[i].title.find(title) != 0)
//		{
//			outputFile << song[i].title << "|" << song[i].artist << "|" << song[i].duration << "|" << song[i].album << "|";
			//cout << title << " has been removed! ";
//			b++;
//		}

//	}


//	outputFile.close();
//	outputFile.clear(std::ios_base::goodbit);

}
Last edited on
Topic archived. No new replies allowed.