How to save information in program and user can use it when he exit the program and Run again. . .

My question is how can i save the information & use again after exiting the program and Run it again.In other words, How can i save my info like that i can use this when i required.
For example,i make a program of save the info about the students,like their name,father name and class or roll No. I want that once i had put this info in program i can be used again.
And how can i add new students and also saving their records.Thanks to all in advance
The most common way to do that is with files. C++ provides the std::ofstream and std::ifstream classes which let you stream to and from files.

http://www.cplusplus.com/doc/tutorial/files/

Note: I recommend not using .open() and .close() - it is better to use RAII.
If u give me an example i will better understand this. . . You can give me example a program that just input user name and store it.user can enter a new name when required. thanks
Untested:
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
#include <iostream>
#include <fstream>
#include <string>

int main()
{
	std::cout << "Enter a filename: ";
	std::string fname;
	if(std::getline(std::cin, fname))
	{
		if(std::ifstream file {fname}) //if we can read the file (e.g. it already exists)
		{
			std::string line;
			if(std::getline(file, line)) //if we can get a line from the file
			{
				std::cout << "The first line of \"" << fname << "\" is \"" << line << "\"." << std::endl;
			}
			else
			{
				std::cout << "The file \"" << fname << "\" is empty." << std::endl;
			}
		}
		else if(std::ofstream file {fname}) //otherwise, try to write to the file
		{
			std::string text;
			if((std::cout << "Enter some text to write to the file: ") && std::getline(std::cin, text))
			{
				if(file << text << std::endl) //if write was successful
				{
					std::cout << "Your text was written to the file." << std::endl;
				}
			}
		}
		else
		{
			std::cout << "Could not read or write the file \"" << fname << "\" - is it valid?" << std::endl;
		}
	}
}
Topic archived. No new replies allowed.