Not printing .txt info

Write your question here.


User.cpp
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  #include "User.h"

string User::getID(){
	return iD;
}

void User::setID(string _ID)
{
	iD = _ID;
}

string User::getName(){
	return name;
}

void User::setName(string _Name)
{
	name = _Name;
}


string User::getAge(){
	return age;	
}

void User::setAge(string _Age)
{
	age = _Age;
}


string User::getGender(){
	return gender;	
}

void User::setGender(string _Gender)
{
	gender = _Gender;
}


string User::getPlaylist(){
	return playlist;	
}

void User::setPlaylist(string _Playlist)
{
	playlist = _Playlist;
}


int User::register_User() 
{

	ofstream myfile;
	myfile.open ("User.txt", fstream::in | fstream::out | fstream::app);

	#pragma region CODIGO_LUIS

	/*char numero[10];
	char nome[256];
	char idade[99];
	char genero[20];
	char list[256];
     
               
	ofstream myfile;
         
 
	myfile.open ("User.txt", fstream::in | fstream::out | fstream::app);

	cout << "ID No. : ";
	cin.getline(numero, 10);
	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
	cout << "User name : ";
	cin.getline(nome, 256);
	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
	cout << "Age: ";
	cin.getline(idade, 99);
	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
	cout << "Gender : ";
	cin.getline(genero, 20);
	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
		  
	cout << "Playlist : ";
	cin.getline(list, 256);
	cin.ignore(numeric_limits<streamsize>::max(),'\n');
	cout << endl;*/

	#pragma endregion CODIGO_LUIS

	myfile << getID() << "," << getName() << "," << getAge() << "," << getGender() << "," << getPlaylist() << endl;
         
	myfile.close();
	return 0;

}

void User::printUser()
{
	cout << ">> User Information" << endl;
	cout << "==========================================================" << endl;
	cout << "ID: " << getID() << "\n";
	cout << "Name: " << getName() << "\n";
	cout << "Gender: " << getGender() << "\n";
	cout << "PlayList: " << getPlaylist() << "\n";
	cout << "==========================================================" << endl << endl;
}

User retrieveUserInfo()
{
	User _newUser = User();
	string _iD, _name, _age, _gender, _playList = ""; 
	
	cout << "ID No. : ";
	getline(cin,_iD);
	_newUser.setID(_iD);
	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
	cout << "User name : ";
	getline(cin,_name);
	_newUser.setName(_name);
	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
	cout << "Age: ";
	getline(cin,_age);
	_newUser.setAge(_age);
	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
	cout << "Gender : ";
	getline(cin,_gender);
	_newUser.setGender(_gender);
	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
		  
	cout << "Playlist : ";
	getline(cin,_playList);
	_newUser.setPlaylist(_playList);
	cout << endl;

	return _newUser;
}


int submain3()
{
    User pessoa;
    vector<User> user;
    ifstream dataFile("User.txt");
 
    if (!dataFile.is_open())
    {
		cout << "ERROR: Cannot open file.\n";
		cin.get();
		return 1;
    }
 
    string line;
 
    getline(dataFile, line);
        cout << "LISTA DE UTILIZADORES DA RADIO\n" << "Utilizadores" << "\n----\n"<< endl;
 
    const char comma = ',';

    while (getline(dataFile, line))
    {
        istringstream ss(line);
                cout << "passei por aqui" << endl;
        getline(ss, pessoa.getID(), comma);
        getline(ss, pessoa.getName(), comma);
		getline(ss, pessoa.getAge(), comma);
        getline(ss, pessoa.getGender(), comma);
        getline(ss, pessoa.getPlaylist(), comma);
       
 
        user.push_back(pessoa);
    }
 
    dataFile.close();
 
    for (int i=0; i<user.size(); i++)
    {
                //cout << music[i].ID << endl;
        cout << "ID:  " << "here" << user[i].getID() << endl;
		cout << "Name:  " << user[i].getName() << endl;
        cout << "Age: " << user[i].getAge() << endl;
        cout << "Gender: " << user[i].getGender() << endl;
        cout << "Playlist:  " << user[i].getPlaylist() << endl;
       
 
        cout << "\n------------------\n" << endl;
    }
 
    string resposta;
    cout << "Do you want do register a new user? (y/n) " << endl;
    cin >> resposta;
	cin.ignore(numeric_limits<streamsize>::max(),'\n');

    if (resposta == "yes")
	{
        pessoa.register_User();
	}
    else
	{
        cout << "Ate a proxima" << endl;
	}

	cout << "UTILIZADOR REGISTADO!" << endl;

    cin.get();
	system("pause");
    return 0;

}


User.h

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
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <limits>

using namespace std;


class User
{

	private:

		string iD;
		string name;
		string age;
		string gender;
		string playlist;
	
	public:

		User(){iD="";name="";age="";gender="";playlist="";}

		User(string _ID, string _name, string _age, string _gender, string _playlist)
		{
			iD = _ID;
			name = _name;
			age = _age;
			gender = _gender;
			playlist = _playlist;
		}

		string getID();
		void setID(string _ID);

		string getName();
		void setName(string _Name);

		string getAge();
		void setAge(string _Age);

		string getGender();
		void setGender(string _Gender);

		string getPlaylist();
		void setPlaylist(string _Playlist);

		int register_User();

		void printUser();
};

User retrieveUserInfo();

int submain3();


Could you tell me why my submain3 isnt working?
It isnt returning my txt info.

1
2
3
4
5
6
cout << "ID:  " << "here" << user[i].getID() << endl;
		cout << "Name:  " << user[i].getName() << endl;
        cout << "Age: " << user[i].getAge() << endl;
        cout << "Gender: " << user[i].getGender() << endl;
        cout << "Playlist:  " << user[i].getPlaylist() << endl;
       


Somehow this isnt working.

Thanks in advance

Best regards
Bump.

Really need this working D:
Could you tell me why my submain3 isnt working?
It isnt returning my txt info.

Well, you haven't defined it as returning any text - you've defined it to return a single integer:

 
int submain3();

Somehow this isnt working.

What do you mean by "isn't working"? What output are you getting?

Have you tried stepping through it in a debugger, to see what's happening?
It's working now.
I was using the function get and ofcourse it wasnt returning a damn thing

heres the fixed code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
if(!line.empty())
		{
			//cout << "passei por aqui" << endl;
			//userList = splitUserString(line);
			//parse(line,",",userList);
			getline(ss, _iD, comma);
			pessoa.setID(_iD);
			getline(ss, _name, comma);
			pessoa.setName(_name);
			getline(ss, _age, comma);
			pessoa.setAge(_age);
			getline(ss, _gender, comma);
			pessoa.setGender(_gender);
			getline(ss, _playList, comma);
			pessoa.setPlaylist(_playList);

			user.push_back(pessoa);
		}


Thanks anyways
Topic archived. No new replies allowed.