|
Hi there.
I am writing a string into a .txt file, but I am getting an extra while space in between each char.
Please suggest me, why this is so.
For Eg. if I write Hello, it will be written as H e l l o.
Thanks
PanB
|
|
|
|
|
I'm going to put on my psychic hat...
You are not getting a space between letters, you are getting a NULL.
Your text in the compiler is a TCHAR, and that defaults to unicode these days.
You're looking at the text in notepad, and it's reading it as ascii...
Read:
http://www.codeproject.com/KB/string/cppstringguide1.aspx[^]
You will be a better person afterwards, and will no longer kick puppies for fun.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Well, welcome again in the CP's Memorable Quotes list [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
If your're passing string something like this, _T("Hai"), according to the unicode settings of project, the string will be treated as unicode characters which means two bytes per character. That's the reason for this issue.
CFile::Write will take any kind of inputs. If you've the string with you,
you can writes as file1.Write( "Hai", 3 ); or convert using WideCharToMultibyte API or W2A conversion macros and then write the file.
If you want to write and save the file as unicode text file, then you will have to add BOM characters before writing to file.
Check this article[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
PankajB wrote: I am writing a string into a .txt file, but I am getting an extra while space in between each char.
Please suggest me, why this is so.
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hello,
ask to help me with 2 problems.
Access-database has password and open by
try
{
hr = m_pConnection->Open(_bstr_t (lpstrConnection), ...);
return hr == S_OK;
}
catch(_com_error &e)
{}
1) When database file has attribute "ReadOnly" catch takes place with NativeError=0xfffff88f and NumberError=80004005 ("Not a valid password").
But when ja reset attribute "ReadOnly", database is opened OK. Why error is detected for Readonly file?
2) How can I recognize that invalid password is in connection string? Which code will be in NativeError for any database type (not only Access)in this case?
Thanks
|
|
|
|
|
Grebeshkova wrote: 1) When database file has attribute "ReadOnly"...
Is it readonly at the OS level or at the application (i.e., Access) level?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi to everyone,
I am breaking my head to find a proper example how to use map of STL in mfc. But didnt get.
Could anyone please help me out with the same. Please give me the exact syntax to use them.
I want to create a map with 3 fields (like a table)
id, name, RegNo
thanks in advance
I am a beginner
|
|
|
|
|
I think a map is between one thing (key) and another thing (object). [*]
But you could package the name and regno in a structure together, then map between the id and otherstuffstruct...
Iain.
[*] someone will now say "but in boost..."
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
himangshuS wrote: how to use map of STL in mfc
Confusing... In MFC there is a map template class named CMap.
- ns ami -
|
|
|
|
|
As suggest by Iain, you may use a struct, for instance, assuming id unique (see, for instance, [^]):
#include <map>
using namespace std;
struct MyData
{
string _name;
int _regNo;
MyData(string name, int regNo): _name(name), _regNo(regNo){}
};
void main()
{
map <int, MyData> mymap;
mymap.insert(pair <int, MyData>(1, MyData("foo", 10)));
}
BTW MFC hai is own CMap container, but keep away from it!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Or this way too.
std::map<int,pair><string,int> > myMap;
myMap[10] = make_pair("cp",10);
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Using STL's std::map from MFC is no different from using it anywhere else. See here[^] for an example.
Steve
|
|
|
|
|
|
Sorry for my repeat post as my previous post crosses so many pages...
I'll explain my problem once again...
I've one database which includes chinese and english character... Now extracting from the database is done..with the help of connection object and query and all other thing..That's not the issue...
Now when i extract the part (Field) which contains both english and chinese character with the help of this..
_bstr_r bstrString_Dest;
bstrString_Dest= m_cpRecordsetSearch->Fields->GetItem("DestinationValue")->GetValue().bstrVal;
Now when i see using quick watch or tool tip it comes "abc??????" question marks are actually chinese character...
Now i do this to write into the file...
stream = fopen(pszwritepath, "ab");
if(stream == NULL)
{
return 0;
}
int n = fwprintf(stream, L"%ls\r\n", (wchar_t*)bstrString_Dest);
It comes to notepad as "abc(aquare brackets)"... Now when i copy the text from notepad and paste to MS-Word or MS-Access it shows perfectly.. i.e "abc(chinese character)"... But when i see same file on chinese machine it shows junk character...
So where am i going wrong?? Is there something encoding compatibility of notepad in my machine and chinese machine?? I'm really stuck in here...
|
|
|
|
|
VC++ is not good at showing you the chinese text. I assume the characters are not in the font it uses. This does not mean the code is bad.
Notepad is just guessing at the encoding, and getting it wrong.
But if you're saving UNICODE, you can help notepad by saving a byte order marker (or BOM) at the front of the file.
I forget it should be FFFE, or FEFF. But as that's only two choices, try both and see which works.
You possibly will also have the problem of fonts having the chinese characters in it in notepad.
Good luck,
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
All right i get it...
stream = fopen(pszwritepath, "ab");
if(stream == NULL)
{
return 0;
}
int n = fwprintf(stream, L"%ls\r\n", (wchar_t*)bstrString_Dest);
Above code is working perfectly... I wasn't selecting unicode while i was seeing in notepad (Silly mistake)... But as i've to make many file how do i make sure that the data which is being writed to notepad open as unicode only not ascii???
Thanks
P.S
Didn't saw ian's post.. Thanks i'll try to do that..
You mean to say before i write to the file i should write that byte order marker (BOM) first???
|
|
|
|
|
gothic_coder wrote: You mean to say before i write to the file i should write that byte order marker (BOM) first???
Yes. See:
http://en.wikipedia.org/wiki/Byte-order_mark[^]
As for mispelling my name... As you're not from the mother country, I'll forgive you. Once. Please warn all of your fellow countrymen to not make the same mistake...
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Iain Clarke wrote: As for mispelling my name... As you're not from the mother country
But he neverthless lives in the Empire...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I have a following code for createing a thread. but it generate the error msg as:
error C2665: 'AfxBeginThread' : none of the 2 overloads could convert all the argument types
CWinThread* mpWinThread;
mpWinThread = AfxBeginThread(&CDataCapture::ThreadProc,NULL,0,0,NULL);
and ThreadProc function is as follow:
UINT ThreadProc(LPVOID pParam)
{
return 0;
}
I am not getting where is the actual problem.
Thanks,
Abhijit
|
|
|
|
|
Hello Abhijit,
As per your code snippet, ThreadProc is a global function and not the member of CDataCapture . Change the code snippet like this.
CWinThread* mpWinThread;
mpWinThread = AfxBeginThread(ThreadProc,NULL,0,0,NULL);
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
It seems that the ThreadProc function is a member function of a class. You can't do that unless the function is static.
|
|
|
|
|
Hi,
May i know how can i get all the key names and values for a section in an ini file....
|
|
|
|
|
Is this helpful GetPrivateProfileSectionNames ?
Regards,
Paresh.
|
|
|
|
|
pradeep455 wrote:
May i know how can i get all the key names and values for a section in an ini file....
I didn't think you could...
But I know the function to read from this is GetPrivateProfileString / Int, so while looking for that function in msn, I stumble across:
MSDN wrote:
The GetPrivateProfileSection function retrieves all the keys and values for the specified section of an initialization file.
Also, GetPrivateProfileSectionNames.
I hope that helps!
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|