Reputation: 292
I'm using a CStdioFile
and trying to leave a number of white spaces before writing a CString.
I tried CStdioFile.Seek(iNumOfSpaces, CStdioFile::current)
the i write the string.
the problem is that when I open the file in Notepad++ it writes NUL instead of the white spaces.
How to write the white spaces to be viewed as white not NUL?
Thanks in advance
Upvotes: 0
Views: 267
Reputation: 415
1.
CString hh="i7mjmhb";
CString h(' ',31);
hh=h+hh;
2.
CString hh=L"i7mjmhb";
CString h(L' ',31);
hh=h+hh;
With files it's bad not to know forward is it ascii or unicode stuff
Upvotes: -2
Reputation: 6556
You misunderstood what CFile::Seek()
method does. It moves the file pointer to a specified position, absolutely or relatively. It does not add/modify the content of the file.
Instead you should use CString::Format()
method that supports padding. Here is an example that shows how to use it:
CString s;
s.Format(_T("|%-10s|"), _T("Data")); // left-align
s.Format(_T("|%10s|"), _T("Data")); // right-align
The result string is going to look like:
|Data |
| Data|
Here is an example that shows how to implement dynamic (variable length) padding:
CString s;
int n = 10;
s.Format(_T("|%-*s|"), n, _T("Data")); // left-align
s.Format(_T("|%*s|"), n, _T("Data")); // right-align
Upvotes: 5