473,473 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with CString's Format

3 New Member
I've used the Cstring format to convernt a CTime into a a CString, yet I get an error message, here's the code:

void CTimerDlg::OnTimer(UINT_PTR nIDEvent)
{
CString m_sTime;
// TODO: Add your message handler code here and/or call default
CTime CurTime = CTime::GetCurrentTime();

m_sTime.Format ("%d,%d,%d", CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond());

UpdateData(FALSE);

CDialog::OnTimer(nIDEvent);
}

The Error message is : error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [9]' to 'const wchar_t *'

How do I do this?
Jul 7 '07 #1
5 11878
Meetee
931 Recognized Expert Moderator Contributor
I've used the Cstring format to convernt a CTime into a a CString, yet I get an error message, here's the code:

void CTimerDlg::OnTimer(UINT_PTR nIDEvent)
{
CString m_sTime;
// TODO: Add your message handler code here and/or call default
CTime CurTime = CTime::GetCurrentTime();

m_sTime.Format ("%d,%d,%d", CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond());

UpdateData(FALSE);

CDialog::OnTimer(nIDEvent);
}

The Error message is : error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [9]' to 'const wchar_t *'

How do I do this?
I think const wchar_t * typed parameter should be passed to CurTime.GetHour() function and you have passes const char [9] types parameter. Which causes such an error
Jul 7 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
m_sTime.Format ("%d,%d,%d", CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond());
If you are using <tchar.h> this should be:
[code=c]
m_sTime.Format (TEXT("%d,%d,%d"), CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond());
Jul 7 '07 #3
ProgMaster
3 New Member
If you are using <tchar.h> this should be:
[code=c]
m_sTime.Format (TEXT("%d,%d,%d"), CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond());
Thank you very much, the code now works perfectly, but could you please tell me what caused the error, becuase I took the code directly from a tutorial about Visual C++. And what does the command "TEXT(..)" do?
Jul 8 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Thank you very much, the code now works perfectly, but could you please tell me what caused the error, becuase I took the code directly from a tutorial about Visual C++. And what does the command "TEXT(..)" do?
TEXT is a macro. If _UNICIODE is defined TEXT becomes L:

Expand|Select|Wrap|Line Numbers
  1. m_sTime.Format (L"%d,%d,%d", CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond());
  2.  
The L means the string is wchar_t characters and not char characters.

If _UNICODE is not defined, the TEXT becomes nothing.

This allows your code to switch between ASCII and UNICODE without having to change the code.

There are lot of things to worry about. Start here.
Jul 8 '07 #5
ProgMaster
3 New Member
TEXT is a macro. If _UNICIODE is defined TEXT becomes L:

Expand|Select|Wrap|Line Numbers
  1. m_sTime.Format (L"%d,%d,%d", CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond());
  2.  
The L means the string is wchar_t characters and not char characters.

If _UNICODE is not defined, the TEXT becomes nothing.

This allows your code to switch between ASCII and UNICODE without having to change the code.

There are lot of things to worry about. Start here.
Thank you very much, the page was very helpul. I'm still a beginner in C++ , and after programming Visual Basic for so long, many things in C++ seem very confusing.
Jul 9 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Boz | last post by:
Hi, I am trying to use string.Format() to output the value of a double. double da = 100000000000.99994; double db = 100000000000.9994; double dc = 100000000000.994; double dd =...
3
by: Sam | last post by:
Hi, I store the date selected in a datetimepicker into a sqlserver table in a SmallDateTime field. To be compatible with the date format of my sql server, I convert the date as following: Dim...
4
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am having a problem formatting a string when the time is in format hh.mm.ss - used in Europe Parse seems ok when the date uses "/" or "." as seperator but I get an exception when time...
0
by: RadhakrishnanR | last post by:
HI ALL, My .NET application devloped in C# used mainly class file (OOAD) and user controls etc and it is desktop application not web based application. Database is SQL server 2000. Now I have...
3
by: n.net | last post by:
Due to the much of VBScript inhibition in my early years of website development, I exhaustively used the following code in my .NET console applications. oLog.setStartTime = Format(Now,...
1
by: saddist | last post by:
Hello, In access 2003 I have date format yyyy/mm/dd, but I want it to be dd/mm/yyyy. I tried to enter dd"/"mm"/"yyyy and dd/mm/yyyy in format property, but it changes automaticly to dd/mm"/yyyy"....
5
manoj9849967222
by: manoj9849967222 | last post by:
Hi All I have a problem with date format. I have designed a table with one of the field as Date. when i enter the date it is comming in mm/dd/yyyy format. Is there a way to change the format to...
4
by: anniebai | last post by:
In our database, the publication year and month are saved in different columns, the query is to find out the pubs after 7/1/2006. My following query works but not get the desired dataset, e.g....
8
by: ncsthbell | last post by:
Access 2007 - I have a temporary table with a column named 'verified_dt' with datatype as date/time. When I look in the table this field is formatted correctly as "10/28/10". This data in this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.