|
nneodeath wrote:
so do i put it this way?
What does the compiler say?
nneodeath wrote:
time = CTime();
CTime is an MFC class. To instantiate one, use:
CTime time; To construct one with the current date and time, use
CTime time = CTime::GetCurrentTime();
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
i tryed it but i doesnt really work could u please show me what i am doing wrong
#include <iostream>
using namespace std;
CTime time;
int main (void)
{
CTime time = CTime::GetCurrentTime();
cout << time << endl;
return 0;
}
this is my code pls help me correct it so that the date and time goes like this
time variebles
HHMM <==this order
date variebles
DDMMYY<==this order
|
|
|
|
|
nneodeath wrote:
cout << time << endl;
Use:
cout << time.Format("%x") << endl;
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
#include<iostream>
using namespace std;
CTime time;
int main (void)
{
CTime time = CTime::GetCurrentTime();
//cout << time << endl;
cout << time.Format(time) << endl;
return 0;
}
the outcome:
--------------------Configuration: tiemsam - Win32 Debug--------------------
Compiling...
tiemsam.cpp
C:\Documents and Settings\nick\Desktop\currently doing cpp project\tiemsam.cpp(4) : error C2146: syntax error : missing ';' before identifier 'time'
C:\Documents and Settings\nick\Desktop\currently doing cpp project\tiemsam.cpp(4) : error C2501: 'CTime' : missing storage-class or type specifiers
C:\Documents and Settings\nick\Desktop\currently doing cpp project\tiemsam.cpp(4) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
tiemsam.exe - 3 error(s), 0 warning(s)
please help me see wats the problem
|
|
|
|
|
Why do you have two CTime variables?
nneodeath wrote:
cout << time.Format(time) << endl;
This is wrong. See my previous post.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Flace wrote:
With _MBCS defined, size of TCHAR is 1 byte, so you cant even multiply _tcslen with this
I'm confused by this statement. But the number of occupied bytes in your string will be :
<br />
int nBytes = (_tcslen(pszString) * sizeof(TCHAR));<br />
The sizeof() will return the number of bytes occupied per character. This will obviously vary depending if you are working in single byte or double byte character mode.
I Dream of Absolute Zero
|
|
|
|
|
If you know you have a multibyte string, you can simply use strlen() to obtain the number of bytes.
void SomeFunction(LPSTR pString)
{
int nChars = _mbslen(pString);
int nBytes = strlen(pString);
[...]
}
If you are using the TCHAR macros you can do it like this:
void SomFunction(LPTSTR pString)
{
int nChars = _tcsclen(pString);
int nBytes = _tcslen(pString) * sizeof(TCHAR);
}
Note _tcslen is different than _tcsclen .
If _UNICODE is not defined, _tcslen resolves to strlen , and sizeof(TCHAR)==1 .
If _UNICODE is defined, _tcslen resolves to wcslen , and sizeof(TCHAR)==2 .
So, _tcslen(pString) * sizeof(TCHAR) will give you the number of bytes in any case.
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Jose Lamas Rios wrote:
If you know you have a multibyte string, you can simply use strlen() to obtain the number of bytes.
can you not have a NULL in the middle of a multi-byte string?
Jose Lamas Rios wrote:
If _UNICODE is not defined, _tcslen resolves to strlen, and sizeof(TCHAR)==1.
If _UNICODE is defined, _tcslen resolves to wcslen, and sizeof(TCHAR)==2.
So, _tcslen(pString) * sizeof(TCHAR) will give you the number of bytes in any case.
If _UNICODE is not defined, and _MBCS is defined, _tcslen resolves to _mbslen. And you know, _MBCS is defined by default in the project settings. So, _tcslen(pString) * sizeof(TCHAR) will not always give you the number of bytes all the time...
|
|
|
|
|
|
Two above posts are correct, except only the one thing. As MSDN says :
"these functions returns the number of characters in string, excluding the terminal NULL."
So, I suppose, the correct answer on the question will be
(_tcslen(str) + 1) * sizeof(TCHAR)
Andrew
|
|
|
|
|
|
Hi all,
Can I make a variable argrument function like foofunc(char*, const char *,...); as a virtual function in C++ class.?.
Thanks in Advance
Abhi Lahare
|
|
|
|
|
|
I dont have a compiler to test this right now, but c++ allow the following two to be present simultaneously? My guess is No. How about the first one in the base class and the second on in the derived class? Myy guess again is no, but this time I am less confident. Can someone clarify with reasons?
foofunc(char*, const char *,...);
foofunc(char*, const char *, int);
|
|
|
|
|
insert a 'does' there - read it as "...,but does c++ allow..."
|
|
|
|
|
Flace wrote:
My guess is No
why?
this works exactly as expected:
class foo
{
public:
virtual void doo(int i, ...)
{
TRACE("foodoo\n");
}
} ;
class voo : public foo
{
public:
virtual void doo(int i, int x)
{
TRACE("voodoo\n");
}
};
...
foo f;
f.doo(0, 0);
voo v;
v.doo(0, 0);
foodoo
voodoo
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
I see. How about this:
foo *f = new doo;
f->doo();
|
|
|
|
|
eeek...I meant foo *f= new voo;
|
|
|
|
|
|
The first one is no surprise as the compiler will pick the method of class on which you are calling the function. The second one is interesting, but it too is not a surprise to me as you have defined doo as virtual in the base class. Can you do a couple more tests:
1. Do not define doo as virtual in foo, and try this:
<br />
foo *f = new voo;<br />
f->doo(3,3); <br />
2. what if both the prototypes are in the same class, which one does the compiler pick:
<br />
class foo {<br />
void doo(int i, ...) {<br />
TRACE ("int i, ...");<br />
}<br />
void doo(int i, int j) {<br />
TRACE("int i, int j");<br />
} <br />
}<br />
foo f;<br />
f.doo(3, 3);<br />
|
|
|
|
|
1. foodoo
2. int i, int j
why do you think this would behave any differently than a function that doesn't have a vararg parameter ?
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
I was basically expecting an error thinking that C++ compiler would get confused in resolving the function call. It looks like the function with explicit arguments takes precedence over the function with varargs.
I wonder how this extends to function pointers...let me experiment this myself tomorrow.
|
|
|
|
|
I have recently tried incorporating someone's codes into my codes in visual c++. However their codes are in C. Anyway I have just added their .C and .H files into my project workspace and called one of their functions in my main program. I am unable to cmpile due to the error below:
regis.obj : error LNK2001: unresolved external symbol "struct Coordinates __cdecl findRotationMatrix(struct Coordinates)" (?findRotationMatrix@@YA?AUCoordinates@@U1@@Z)
Debug/regis.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
I understand that the compiler is looking for a library file but the problem is the codes i downloaded only came with the .C and .H file. If i am not wrong, the original codes were compiled successfuly in gcc. Is this a compatability problem?
|
|
|
|
|
findRotationMatrix is this declared in .h ?
|
|
|
|