Once info has been written into txt file, edit through command prompt

I've posted the same question on this forum before. However, I failed to reply early to a user that attempted to help out and I think the question has been lost in the forums amongst all the other questions.

http://www.cplusplus.com/forum/general/235349/


So with the help of the guys here I've managed to create a vector that stores information into a txt file.

The system function as stated below, Staff can
1) Add station (no limitation to how many can be added, station info consists of 4 strings and 1 int that have to be added)
2) View Stations (simply read the station txt file above)
3) Edit stations

The issue I'm currently facing is editing the stations. I would like to do so through the command prompt, I am not sure how exactly this will be accomplished. If the user simply drags the mouse over to the information he would like edited and starts removing/adding information that would be ideal.

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
void Staff::ManageSelangorRailway()
{
	int select;
	cout << "Please select one of the following options: \n\n";
	cout << "1) Add Station 2) Edit/Delete Station 3) View Station 4) Return";
	cin >> select;

	switch (select)
	{
	case 1:
	{
		vector <StationInfo> getStationInfo;
		ofstream out("SelangorStations.txt", ofstream::out | ofstream::app);
		char accept = 'y';
		char reject = 'n';
		while (tolower(accept) == 'y')
		{
			StationInfo stationInfo = GetStationInfo();
			getStationInfo.push_back(stationInfo);
			cout << endl;
			out << stationInfo;

			cout << "Would you like to add another station ? (y/n): ";
			
			if (cin >> accept)
			{
				out.close();
				Staff::Staff();
			}
			else if (cin >> reject)
			{
				Staff();
			}
		}
		break;
	}
	case 2:
	{
		
	}


I have searched quite a few resources and attempted to edit the code in order to make it work with mine, does not seem to be working though.

Not sure if I should fill up the question up with my failed attempts. If any of you want them I'll share.

At this point would anyone mind, writing out the code. I'm burnt out and would love nothing more then to understand it by actually looking at the code.
Last edited on
You can't do this with C++ alone. It doesn't control mouse movements or press buttons or anything like that. The only way would be to use some widgets from external libraries.

As @repeater pointed out to you in the earlier post, "edit" effectively means "replace".
Give the user a numbered list of available stations, let him choose a number (or add a new one) and give him a text menu to enter new data.

Forget mouse movements/clicks unless you are really handy with external libraries. Standard c++ alone will not do it.
Alright, no moue movements or clicks. I've attempted to assign each station added into the vector a unique ID (so far haven't got it working).

I've attempted to read txt files and edit them with and without mouse movement. But I just cant seem to understand how to do it.

As stated in the earlier post I've been trying to do it for a couple of days now but just cant seem to get it right. I'd appreciate it if you or anyone else could actually write out the code to be able to read and replace the stations, at this point I don't mind dropping the unique ID per station idea.
Topic archived. No new replies allowed.