Search
 
SCRIPT & CODE EXAMPLE
 

CPP

read variable to file cpp

int main()
{
  	// writing process
    char name[20], phone[20];

    cout<< "Enter your name: ";
    cin>> name;
    cout<< "Enter you phone number: ";
    cin>> phone;

    ofstream file_w ("test.txt");

    file_w << name <<endl
           << phone<<endl;

    cout << "Process complete";
    file_w.close();
	
  	// reading the vairable's values
    ifstream file_r ("test.txt");

    char Name[20], Phone[20];

    file_r >> Name >> Phone;

    cout<< "Name = " << Name << endl << "Phone = " << Phone ;

    return 0;
}
Comment

write variable to file cpp

int main()
{
    char name[20], phone[20];

    cout<< "Enter your name: ";
    cin>> name;
    cout<< "Enter you phone number: ";
    cin>> phone;

    ofstream file_w ("test.txt");

    file_w << name <<endl
           << phone<<endl;

    cout << "Process complete";
    file_w.close();
  
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: distinct colors cses solution 
Cpp :: cout hello world 
Cpp :: C++ Converting Kelvin to Fahrenheit 
Cpp :: use regex replace in c++ 
Cpp :: sqrt cpp 
Cpp :: delete specific vector element c++ 
Cpp :: crypto npm random bytes 
Cpp :: qlabel set text color 
Cpp :: cpp random number in range 
Cpp :: how to display a variable in c++ 
Cpp :: Modulo Exponentiaon,Iteratve Modulo Exponentiation 
Cpp :: setw in c++ 
Cpp :: string to int arduino 
Cpp :: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools" 
Cpp :: check if point is left or right of vector 
Cpp :: how to get input in cpp 
Cpp :: string input with space c++ stl 
Cpp :: C++ Multi-line comments 
Cpp :: opencv rgb to gray c++ 
Cpp :: how to run a msi file raspbrain 
Cpp :: c++ char to uppercase 
Cpp :: how to do nCr in c++ 
Cpp :: length of string c++ 
Cpp :: c++ vector fill 
Cpp :: Write C++ program to sort an array in ascending order 
Cpp :: cpp multidimensional vector 
Cpp :: read comma separated text file in c++ 
Cpp :: concatenate string program in c++ 
Cpp :: c++ get character from string 
Cpp :: stl sort in c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =