Home > Back-end >  C string object in the file access
C string object in the file access

Time:10-05

#include
#include
#include
using namespace std;

Class A
{
Public:
A () {};
A (string A) : (A) A {}
Show () {
Cout}
Private:
String a;
};

Void main ()
{
/* aa (" fdsfefefd ");
A.s how ();
Ofstream OS (" gao ", ios_base: : binary);
OS. Write (reinterpret_cast & lt; Char * & gt; (& amp; A), sizeof (a));
OS. The close (); */
A, b.
Ifstream is (" gao ", ios_base: : binary);
Is. Read (reinterpret_cast & lt; Char * & gt; (& amp; B), 16);
B.s how ();

}
Can run after cancellation of the notes, annotations can't read running after failure, the reason is a string of problems, but if we don't change this kind of operation, what's the solution?

CodePudding user response:

Ifstream ofstream are to the operation of the file, so you write: ofstream OS (" gao ", ios_base: : binary); Ifstream is (" gao ", ios_base: : binary); If there are any questions around? In addition: is. Read (reinterpret_cast & lt; Char * & gt; (& amp; B), 16); Instead, turn a statement into public, is. Read (reinterpret_cast & lt; Char * & gt; (& amp; (b.a)), 16); Have a try
  • Related