Questions tagged [cfile]

The cfile tag should be used for questions about the CFile and CStdioFile classes (and their relatives) in MFC (Microsoft Foundation Classes) for C++ code. You should normally add the C++ (or possibly Visual-C++) and MFC tags too. It is not appropriate for questions tagged C — use the plain 'file' as the tag for such questions.

See CFile class and CStdioFile class on the Microsoft Documentation site for two primary references.

47 questions
17
votes
3 answers

UTF-8, CString and CFile? (C++, MFC)

I'm currently working on a MFC program that specifically has to work with UTF-8. At some point, I have to write UTF-8 data into a file; to do that, I'm using CFiles and CStrings. When I get to write utf-8 (russian characters, to be more precise)…
SeargX
  • 117
  • 1
  • 2
  • 10
3
votes
2 answers

How to make C++ code faster: Creating .csv file from camera data using CFile

A high level overview is that 'CFile file's 'file.write()' method gets called for every individual integer data value (line 9) along with line 12, where I write a comma to file. That means that for 327,680 input data integers, there are 2*327,680 =…
Daniel Ramsey
  • 177
  • 1
  • 2
  • 9
2
votes
1 answer

CFile & CStdioFile produces different results in writing & reading

To my understanding, when creating with typeBinary flag, CFile & CStdioFile should works indentically, except the latter is buffering the data so has a better performance. So I write the following codes to confirm this: ULONGLONG GetRand(ULONGLONG…
alancc
  • 487
  • 2
  • 24
  • 68
2
votes
1 answer

Is there any way to speed up frequent file write operations? CFile

My task is to write small parts of data to file frequently and guaranteed. It's a some type of logging system, that must provide a guaranteed safety and speed of saving data to disk. I found that brakes appear in the Flush() function that is called…
yurart
  • 593
  • 1
  • 6
  • 23
2
votes
1 answer

Getting error message from CStdioFile::Open()?

If CStdioFile::Open fails, I want to be able to report the cause of the error. However, it appears as though it never throws an exception. Also, when I try the following: CStdioFile file; CFileException exc; bool bSuccess =…
des4maisons
  • 1,791
  • 4
  • 20
  • 23
2
votes
1 answer

How can I read a CLongBinary field from my database and write it into a CFile object?

im using a CRecordset to get data from my SQL Server. One table stores a binary file (pdf, odt, ...). My VisualStudio maps the columns to a CLongBinary field. How can I read and open the file from the CLongBinary field? im using some ancient version…
Jakob
  • 778
  • 3
  • 9
  • 25
2
votes
3 answers

How to get a CString object from a file with CFile::Read() in Unicode?

The charset is Unicode. I want to write a string of CString type into a file, and then read it out from the file afterwards. I write the string into a file with CFile::Write() method: int nLen =…
quantity
  • 4,051
  • 3
  • 23
  • 20
1
vote
1 answer

Can file pointer change during the process of write or read of a CFile object

I have a CFile object, which can be accessed by multiple threads. There is the possibility that one thread is writing data to this file while another thread is reading data from the file. I want to know is there any unsafety under this policy? Can…
quantity
  • 4,051
  • 3
  • 23
  • 20
1
vote
1 answer

C++ Can't read UTF-8 cyrillic text from file

The file is UTF-8 (65001) encoded. I can't read cyrillic symbols from it. CString FNAME; CStdiofile fNFR; fNFR.Open(_T("LFS200.25"), CFile::modeRead); fNFR.ReadString(FNAME); And got this: Р—РёРјРЅРёР№ максимум 1989/90 РіРі. instead of…
Nika_Rika
  • 613
  • 2
  • 6
  • 29
1
vote
1 answer

Using CStdioFile for writing string

I want to write data stored in a vector into a file. Therefore I use the following routine: bool Grid::saveToFile() { stringstream sstream; for (size_t i = 0; i < taglist.size(); ++i) { if (i != 0) sstream << ","; …
Michen
  • 51
  • 2
  • 10
1
vote
2 answers

What happened if CFile::Write throws an exception?

Assume that write operation throws an exception half-way. Is there any data written into the file, or is no data written in the file?
user26404
  • 1,371
  • 4
  • 27
  • 38
1
vote
0 answers

How to find logical length of the file in bytes in C#

I am trying to re-write a part of my application from ATL/COM(C++) to WPF, C#. In the older application they use m_inputFile = new CFile(fileName,CFile::modeRead); DWORD fileLength= (DWORD) m_inputFile->GetLength(); But when I use FileInfo.Length…
user2495173
  • 311
  • 2
  • 5
  • 17
1
vote
1 answer

Read and convert Monochrome bitmap file into CByteArray MFC

In my MFC project, I need to read and convert a Monochrome bitmap file into CByteArray. While reading the bitmap file by using 'CFile' class with the mode of 'Read', it seems like it gives more length than its original. My MFC code:- CFile…
1
vote
1 answer

CFile write function

I have got a question about the MFC CFile write function. I am learning about MFC application and stuck at this Save As and write function. When I click the TestButton, a save as dialog box would pop out prompting to save as txt file. void…
Ashton
  • 83
  • 1
  • 3
  • 12
1
vote
1 answer

CFile reads 0 bytes

When using a CFile, for Some reason my call to read() returns 0 bytes after the first call CFile iniFile; int bytesRead=0; char buffer[_MAX_PATH]; if(iniFile.Open(iniDirFilename,CFile::modeRead)){ bytesRead +=…
Shabbir Hussain
  • 2,600
  • 2
  • 17
  • 25
1
2 3 4