|
I found from documents that the strptime is derived from strftime...
But they have not given any implementations for strptime...
Please get me some tips...
|
|
|
|
|
Arun John wrote: But they have not given any implementations for strptime...
No implementation is given?!
The only strptime() I know of is from the OpenGroup[^]. And their documentation page for strptime()[^] has description about the function and an example too.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Can someone tell me how can I set background color of other application for which I donot have code.
Thanks
|
|
|
|
|
You must be get a hdc to other programs.
|
|
|
|
|
|
It depends to your work you can use of Enumchldwindow or use of FindWidow after you get a hwnd you can use of HDC hdc::GetDC(hwnd);
|
|
|
|
|
Hi,
I have recently started learning C++, having come from a mainly Java/PHP background. I am implementing a Poker library, which is something I do in each new language I learn, as porting the code seems a good way to learn syntax of languages. I have a class for data about single cards in the library:
Card.h
class Card
{
..snip..
const static int CLUBS = 0;
const static int DIAMONDS = 1;
const static int HEARTS = 2;
const static int SPADES = 3;
..snip..
public:
..snip..
string toString();
int charsToIndex(char rank, char suit);
};
Card.cpp
string Card::toString()
{
string s("");
s += getRankChar(getRank());
switch (getSuit())
{
case HEARTS: s+='h'; break;
case DIAMONDS: s+='d'; break;
case CLUBS: s+='c'; break;
case SPADES: s+='s'; break;
}
return s;
}
This code compiles and works fine, and passes all the unit tests I have implemented. However when I try to do the "reverse" of this action, I get a number of compiler errors:
Card.cpp
int charsToIndex(char rank, char suit)
{
int r = -1;
switch (rank) {
case '2': r = TWO; break;
case '3': r = THREE; break;
..snip..
}
int s = -1;
switch (suit) {
case 'h': s = HEARTS; break;
case 'd': s = DIAMONDS; break;
..snip..
}
}
The errors are "card.cpp(155) : error C2065: 'TWO' : undeclared identifier", repeated for each time I have used a constant within the charsToIndex function. I can't work out whether I have missed something stupid, or there's something about scope in C++ I don't quite understand.
Thanks in advance for any assistance.
|
|
|
|
|
You need the class id.
<br />
int Card::charsToIndex(char rank, char suit)<br />
{ <br />
..snip.. <br />
}<br />
|
|
|
|
|
may you add these lines before class Card
#define TWO "TWO"
#define THREE "THREE"
I hope it works.
|
|
|
|
|
From your code snipet it is not clear whether you declared TWO in the first place.
Also, allow me to give you a couple of suggestions: your code really looks like Java, and that is not a good way to write C++. I suggest you find a good C++ book, like Accelerated C++[^] and start from there.
Good luck
|
|
|
|
|
Replace this:
faceninja wrote: const static int CLUBS = 0;
const static int DIAMONDS = 1;
const static int HEARTS = 2;
const static int SPADES = 3;
with this:
enum Suit_t
{
CLUBS,
DIAMONDS,
HEARTS,
SPADES
};
Next replace all references to suit, such as underlined below, with Suit_t . ie. This:
int charsToIndex(char rank, char suit);
Should look like this:
int charsToIndex(char rank, Suit_t suit);
Steve
|
|
|
|
|
Thanks for all the assistance. As far as compiling goes, changing the function declaration to "int Card::charsToIndex(char rank, char suit)" makes it compile and run fine.
Thanks for the advice on how to make the code better C++ as well. Having come from a Java backgroud, I'm sure it's going to take me a while to get used to all the nuances of the language 
|
|
|
|
|
hi
i have this function:
int CBmpDlgDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBitmapDialog::OnCreate(lpCreateStruct) == -1)
return -1;
CString path;
if (vbGetCommandLine()!=" ")
{
if (vbGetCommandLine().Left(1)==CString(char(34)) && vbGetCommandLine().Right(1)==CString(char(34)))
{
path = vbGetCommandLine().Mid(2-1, (vbGetCommandLine().GetLength()-2));
}
else
{
path = vbGetCommandLine();
}
}
CFile f;
f.Open(path, CFile::modeRead);
CArchive ar(&f, CArchive::load);
ar >> m_EDIT1 >> m_EDIT2 ;
ar.Close();
f.Close();
return 0;
}
where the vbGetCommandLine() func is as follows:
CString vbGetCommandLine()
{
CString CommandLine;
for (int i=1; i<__argc; i++) {
if (i!=1) CommandLine += " ";
bool flSpace = strchr(__argv[i],' ') ? true : false;
if (flSpace) CommandLine += '"';
CommandLine += __argv[i];
if (flSpace) CommandLine += '"';
}
return CommandLine;
}
the main idea here is: after saving the file with any data it contains....
when i double click it ...it should open ..first by checking the path of the file then open that file.
ok..my question is ...in "OnCreate()" . exactly in f.open()...if i specified the path like "abc.ccc" it works
but when i put open(path)it wont.
although i checked the path value by amessage box and it showed me that i had the correct path ...this is driving me crazy....
so pleease i would be thankful for any kind of help
|
|
|
|
|
what you are doing in vbGetCommandLine() you are trying to form a single string while the command line is already managed to separate the parameters to separate buffers (argument vectors __argv) and you are trying to bound with quotes if a single parameter has space, do you know if the parameter has space it is split into individual __argv element. These should be taken care when executing the application.
lahom wrote: the main idea here is: after saving the file with any data it contains....
when i double click it ...it should open ..first by checking the path of the file then open that file.
if you want to get the file path, just take the first argument, better is to parse the parameters for flags,
Since you are using MFC, you can use CWinApp::ParseCommandLine, in the application InitInstance do the following,
BOOL <yourappclass>::InitInstance()
{
....
CWinApp::InitInstance();
....
<big>CCommandLineInfo cmdinfo;
ParseCommandLine(cmdinfo);</big>
CBmpDlgDlg dlg;
<big>dlg.m_strFileName = cmdinfo.m_strFileName; </big>
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
.....
and in the InitDialog of your dialog class open the file,
BOOL CBmpDlgDlg ::OnInitDialog()
{
CDialog::OnInitDialog();
....
CFile f;
f.Open(<big>m_strFileName</big>, CFile::modeRead);
CArchive ar(&f, CArchive::load);
.....
|
|
|
|
|
thanks for ur reply
Rajkumar R wrote: // set the file name to the member of your dialog class so that in the InitDialog create the file
what do u mean by m_strFileName
|
|
|
|
|
Obvious, declare a member variable for your Dialog class,
class CBmpDlgDlg: public CDialog
{
public:
CString m_strFileName;
|
|
|
|
|
ok
it works ..but when i put
CFile f;
f.Open(m_strFileName, CFile::modeRead);
CArchive ar(&f, CArchive::load);
in OnCreate() not onInitDialog() ...
but there is something.... the file i saved earlier opens fine...but
i cant run the program now it shows me a debug assertion failed..
what is wrong now
|
|
|
|
|
debug assertion will direct you to find what is the failure and where it happens.
what prevents you to code in onInitDialog, it is the override for doing dialog initialization, OnCreate is called before creating the child controls if i remember correctly.
|
|
|
|
|
Rajkumar R wrote: debug assertion will direct you to find what is the failure and where it happens.
the debug assertion happend in :
file:filecore.cpp (where is this ????)
line:220
Rajkumar R wrote: what prevents you to code in onInitDialog, it is the override for doing dialog initialization, OnCreate is called before creating the child controls if i remember correctly.
well,i tried to code in onInitDialog() but then the saved files open but empty . where in onCreate() it opens and retrieve the saved data.
ps:both ways lead to debug assertion when running the program.
it confusing me.. 
|
|
|
|
|
but you can trace the call stack to find the origin of failure in your code, and when debugging at assertion the exact position of code not yours may be filecore.cpp you get the hint.
|
|
|
|
|
i debg the application and find the debug assertion failed in this line:
UINT CFile::Read(void* lpBuf, UINT nCount)
{
ASSERT_VALID(this);
ASSERT(m_hFile != (UINT)hFileNull);
so now iam stuck and i dont know what to do
|
|
|
|
|
It seems file is not opened properly, you need to check the return value of CFile::Open and the get the error status by passing CFileException parameter and you can get the error string using CFileException::GetErrorMessage. the usage is given in [CFile::Open^].
if a function returns other than void you should properly check the return value other wise what is the need of return value, by the way check whether path is correct.
f.Open(path, CFile::modeRead);
|
|
|
|
|
Using Visual C++ 6.0 MFC in SDI.
I'm basically a C programmer doing C++ with MFC. I'm trying to understand what "Serialization" does for me in terms of file I/O. I would like to use the MFC SDI file menu items, but simply code my file input/output in basically the oldstyle - just opening and closing files and storing and retrieving the variable info that is necessary for my program. Is it simple to mix the oldstyle file I/O with the SDI file menu handling items or do I need to learn about serialization?
Thanks ahead of time.
|
|
|
|
|
If you need to store and retrieve objects, serialization is better.
IMHO exploiting MFC 's serialization is also amusing.
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
|
|
|
|
|
XML serialization is even better.
also, one has to be very careful with serialzed filed if moved from one system to another, because some types can be written/read differently depending on the system...
|
|
|
|