getline not working?

Hello again gents,
Im at my wits end, My program is designed to search through a .mp3 file find the id3v1.1 information, output it to console and then offer the chance to alter the comment section... my plan was to enter this information into a string and then use ofstream to write it into the file. I used getline earlier in the program and it worked fine however now that I am in the final stages of course something has gone wrong.. below is my code any help would be great! please forgive all the commented out areas that was just debugging :)

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

struct idestruct{
	char header[3];
	char title[30];
	char artist[30];
	char album[30];
	char year[4];
	char comment[29];
	char track; 
	char genre;
};

/*struct test{
	char comment[29];
	char track;
	char genre;
};*/
	
int main()
{
	ifstream fin;
	char select;
	char genre[126][128] = {"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Regae", "Rock", "Techno",
							"Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental",
							"Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic",
							"Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Souther Rock", "Comedy", "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", 
							"Native American", "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll",
							"Hard Rock", "Folk", "Folk-Rock", "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", 
							"Psychadelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony",
							"Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", "Punk Rock",
							"Drum Solo", "Acapella", "Euro-House", "Dance Hall"};

	int track, genre_num;
	string file, filename, filetype, header, year, comment;
	
	idestruct ide;
	int ide_size = sizeof(ide);
	int comment_loc = 31;

	cout << comment_loc << endl;

	cout << "Enter your MP3 filename: ";
	getline(cin, filename,'.');
	getline(cin, filetype);

	if(filetype != "mp3")
		{
			cout << "Sorry that is not a valid MP3 file. Program Terminating" << endl;
		}
		
	else
	{
		file = filename + '.' + filetype;

		//cout << file << endl;



		fin.open(file.c_str(), ios::binary | ios::in);

		fin.seekg(-(ide_size), ios::end);

		//cout << fin.tellg() << endl;

		fin.read((char *) &ide, (ide_size));

		for(int i = 0; i < 3; i++)
			{
				header += ide.header[i];
			}
		for(int i = 0; i < 4; i++)
		{
			year += ide.year[i];
		}

		if(header != "TAG")
		{
			cout << header << endl;
			cout << "There is no valid header on the file. Program Terminating" << endl;
		}
		else
		{
			cout << "File is OK and has a valid ID3v1.1 " << header << endl << endl;
			cout << "Title: " << ide.title << endl;
			cout << "Artist: " << ide.artist << endl;
			cout << "Album: " << ide.album << endl;
			cout << "Year: " << year << endl;
			cout << "Genre: " << genre[ide.genre] << endl;
			track = static_cast<int>(ide.track);
			cout << "Trank Number: " << track << endl;
			cout << "Comment: " << ide.comment << endl;
			cout << endl;

		}


		
	}





	cout << "Would you like to update the comment? [Y/N]: ";
	cin >> select;
	select = toupper(select);

	switch(select)
	{
		case 'Y':
		{
			//test idetest;

			ofstream fout;
			fin.seekg(-(comment_loc), ios::end);
			//cout << fin.tellg() << endl;
			//fin.read((char *) &idetest, sizeof(idetest));
			//cout << idetest.comment << endl;
			
			cout << "Enter new information for the comment: ";
			getline(cin, comment, '\n');
			cout << comment << endl;


		}
	}
		
	

	

	



	return 0;
}
Line 64 you attempt to open and always assume the file was found and opened successfully - what happens if the file wasn't opened because it didn't exist?

After line 110 where you ask do they want to update the comment, the newline left in the stream buffer will be causing Line 126 to skip. Add cin.ignore(1, '\n'); after Line 110
something has gone wrong

Can you be more specific? What happens when you run the program? Providing the exact input and output would be helpful.
sorry dhayden, what went wrong was that line 164 was skipped.. the cin.ignore fixed that :)..

ah yes i see what you mean, it does open as it reads in the data but youre right i should have it there.. thanks guys
just for my own knowledge why did it ignore it?
Keeping things simple..

As you know, cin waits for the user to enter some value followed by the <Enter> key. When the user hits <Enter> an invisible \n (newline) is included at the end of whatever you entered.

So if I type Y, it appears in memory as Y\n

cin skips all leading whitespace, i.e spaces, tabs and newlines and therefore very importantly cin does not read in the newline leaving it in the buffer (keep that thought). So when you come to use getline which is a instruction to read more data (unlike cin this doesnt skip newline etc) it then sees the \n which was left behind and thinks you have pressed the <Enter> key.
Topic archived. No new replies allowed.