Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

binary file in c++

    //writing into a binary file
		            //int
	fstream bFile("Binary file.dat", ios::out | ios::binary);
	int x = 65;
	if (bFile.is_open()) {
		bFile.write((char*)&x, sizeof(x));
		bFile.close();
	}
	else cout << "Failed opening the file";

			       	//string
fstream binaryName;
	string s = "J.L";
	binaryName.open("Name.dat", ios::out | ios::binary);
	if (binaryName.is_open()) {
		binaryName.write(s.c_str(), s.size());
		binaryName.close();
	}
	else cout << "Unable to open the file!";
 
PREVIOUS NEXT
Tagged: #binary #file
ADD COMMENT
Topic
Name
6+2 =