Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

How to write LONGLONG data in a File

I want to write LONGLONG data (which is 64 bit integer) in a file. How can I do so?
0
asger_cse
Asked:
asger_cse
1 Solution
 
asger_cseAuthor Commented:
Give a sample code also.
0
 
martynjpearsonCommented:
There are loads of ways - if you want to write to the file as binary (i.e. not a text file) you can do this :

__int64 i64MyInt = 1234;
CFile fileOut("C:\\MyFile.bin", CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite);
fileOut.Write((void *)&i64MyInt, sizeof(__int64));
fileOut.Close();

This can then be read in a similar way, passing the address of the __int64 as the buffer, and sizeof(__int64) as the buffer size.

If you want to write it to a text file, you can do this :

__int64 i64MyInt = 1234;

CString strLine;
strLine.Format("%I64d", i64MyInt);

CStdioFile fileOut("C:\\MyFile.txt", CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite);
fileOut.WriteString(strLine + "\n");
fileOut.Close();


Hope this helps
Martyn
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now