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 :: print 5 table in c++ 
Cpp :: fibonacci in c++ 
Cpp :: max three values c++ 
Cpp :: HOW TO TURN LINK TO BUTTON IN MVC 
Cpp :: cout hello world 
Cpp :: c++ remove whitespace from string 
Cpp :: remove () not working c++ 
Cpp :: cpp infinity 
Cpp :: n queens c++ 
Cpp :: #pragma once in main file what is it for 
Cpp :: how to declrae an array of size 1 
Cpp :: cpp float to int 
Cpp :: setw in c++ 
Cpp :: make random nuber between two number in c++ 
Cpp :: how to loop a 2 dimensional vector in c++ starting from second element 
Cpp :: 2d array using vector 
Cpp :: cin.get vs cin.getline in c++ 
Cpp :: how to run a c++ program in the background 
Cpp :: delete file cpp 
Cpp :: c++ merge sort 
Cpp :: how to find length of character array in c++ 
Cpp :: cases in cpp 
Cpp :: c++ typedef 
Cpp :: bubble sort in c+ 
Cpp :: print all elements of vector c++ 
Cpp :: c++ if in equivalent 
Cpp :: less than operator overloading in c++ 
Cpp :: splice string in c++ 
Cpp :: c++ isalphanum 
Cpp :: c++ remove numbers from vector if larger than n 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =