Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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;
}
 
PREVIOUS NEXT
Tagged: #read #variable #file #cpp
ADD COMMENT
Topic
Name
7+4 =