info from a vector to a textfile

I've been working a program which takes information from a textfile puts it into a vector and once I'm done at the end a function quit_program will save and quit.

I have a function called add_name and delete_name and once I've either added or deleted a name to my vector, I need to take it from the vector and place it into my text file once im finished.

this is my read_file function which reads the text file and puts it into a vector

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  int read_file(string strFileName, vector<string>&vecThisStudent, ifstream &inFile)
{

	string strFirstName, strLastName;

	inFile.open(strFileName.c_str(), ios::in | ios::out | ios::app);

	while (inFile >> strFirstName >> strLastName)
	{
		vecThisStudent.push_back(strFirstName + " " + strLastName);
	}

	return 0;


}



here is my add_name function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void add_name(vector<string>&vecThisStudent)
{
//write the body of the function
	string strFirstName, strLastName;

	cout << "------------------------------------------\n";
	cout << "Enter the name to be added (First, Last): ";
	cin >> strFirstName >> strLastName;

	vecThisStudent.push_back(strFirstName + " " + strLastName);

	cout << " -----Name '" << strFirstName << " " << strLastName << " ' has been added.\n";

	

}


and here is my quit_program function which save and quits

1
2
3
4
5
6
7
8
9
void quit_program(string strFileName, vector<string>&vecThisStudent)
{

//Hint: this is the function you should write the vector’s content back to the file.



cout<<"Thanks for using the program. Program terminated"<<endl;
}

Topic archived. No new replies allowed.