|
Thanks for you answer, that makes things very clear.
Ed
|
|
|
|
|
Hello,
I'm looking for suggestions on how to design an text input file. I imagine that each line of the file would look something like this:
Operation argument1 argument2 argument3 etc.
I understand how to do file input if you just want to read one word at a time using the >> operator, but I'm not sure how to "check" what the incoming input is. For example, if a line in the input file started with the operation "CreateNewAccount", how do I (programmatically) check what the string says? If I use std::string for the input the >> operator doesn't seem to like it. If I use char arrays, I can't seem to get two strings to be recognized as equal.
Thanks you for suggestions for how to do this, or perhaps for better ways to go about it. If there is any part I need to clarify let me know.
-Jordan Atlas
|
|
|
|
|
To be more specific about the problems I was having:
I wanted to try to read the words into string variables so that I could compared them to strings indicating which reaction they correspond to. However, if I try to read the words into std::string variables using something like:
inFile >> tempString;
then I get a compiler error:
error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >' (or there is no
acceptable conversion)
I also tried reading the words into char arrays so that I could comapare the char arrays to the string corresponding to a particular operation. If I do that, however, then the comparison doesn't seem to work. Ie: If I read the word "Account" into a char array called charTemp, the statement (charTemp == "Account") seems to evaluate to false (even tho my intention would be for it to be true).
I hope that clarifies the problem rather than making it more complicated!
Again, I am open to alternative suggestions.
-Jordan Atlas
|
|
|
|
|
Jordan C. Atlas wrote:
inFile >> tempString;
then I get a compiler error:
error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no
acceptable conversion)
#include <string>
Jordan C. Atlas wrote:
the statement (charTemp == "Account") seems to evaluate to false
You are comparing two pointers that point to different things so they are obviously not equal. To compare the contents of char arrays you have to use strcmp() .
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Thank you - your answer makes sense. I will continue writing the input file using strings.
-Jordan Atlas-
|
|
|
|
|
How To Use at Crystal Report in Visul c++
|
|
|
|
|
|
Hello,
there seems to be a problem with this code:
RECT pos = {0,0,0,0};
dc.DrawText("Hello 1", &pos, DT_CALCRECT);
dc.TextOut(0,20,"Hello 2");
only "Hello 2" will be printed out. Why is that? Shouldn't DrawText work as well?
Many thanks in advance!
|
|
|
|
|
The DT_CALCRECT flag tells DrawText to calculate the size of the rectangle needed to draw the text, DrawText does not do any actual drawing if this flag is used.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hello,
I have an application using a stream based socket that is set up to look for asynchronous events. When attempting to connect I get a WSAEWOULDBLOCK error which usually happens because the connection cannot complete immediately.
Therefore, I want to use the select() function to wait based on a timer value until the socket is ready for reading. If it is never ready then the function will time out.
Can someone show me an example of how to use the function? I am having some trouble using Winsocks documentation to set it up.
Thanks.
Jerry
|
|
|
|
|
http://www.gamedev.net/reference/articles/article1494.asp
http://www.gamedev.net/reference/articles/article1297.asp
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
When using _malloc_dbg( size, _NORMAL_BLOCK, __FILE__, __LINE__ ), it reports a memory problem if the memory is not freed.
now, if I have a function that wraps malloc ( and _malloc_dbg ), the line reported by _malloc_dbg will be inside that wrapper function; and not from where that wrapper was called.
void* MyMalloc( int size )
{
void* p = NULL;
...
#if _DEBUG
p = _malloc_dbg( size, _NORMAL_BLOCK, __FILE__, __LINE__ );
#else
p = malloc( size );
...
return p;
}
Is there an easier way to have __FILE__ and __LINE__ from the caller without having to create a different wrapper for the debug and release versions ?
Now, I have #define in my code that will either call _malloc_dbg or my own wrapper.
I hope it's clear enough.
Thanks.
Max.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Why not do it the same way MFC does it with new and DEBUG_NEW?
#ifdef _DEBUG
#define MyMalloc(size) MyMallocFunction((size), __LINE__, __FILE__)
#else
#define MyMalloc(size) MyMallocFunction((size), 0, NULL)
#endif
...
void *MyMallocFunction(int size, int line, LPCTSTR file)
{
void* p = NULL;
...
#if _DEBUG
p = _malloc_dbg( size, _NORMAL_BLOCK, file, line );
#else
p = malloc( size );
...
return p;
}
In your client code you just call MyMalloc(100) and it will work just the way you expect.
[edit]the stricked out #else block is not needed[/edit]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
well, I ended up doing something similar ...
Thanks.!!
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I'm new to the board, so please forgive me if this has been discussed before....
I need a way to keep track of how many instances of an application are running, and a way to distinguish between them. My main app loads other aps selected by the user and needs to communicate with them to get them to store their settings in the registry. If the apps are the same name, they will write their settings to the same registry key, and I don't want that.
I thought about just sending an instance # to the app on the command line, but if one app is closed, I need to know this and adjust the instance # of the remaining ones. If none of this makes sense, I'll explain more later.
Thanks
Joe Andrews
|
|
|
|
|
if you send an ID to an app, does it need to be "permanent" ? can you launch an unlimited number of the same application ? because if they also write settings to the registry, each app needs to have a permanent ID, and you don't want to change the app's ID.
for example, I launch app A 3 times, I will have A(1) A(2) and A(3); if I close A(2), A(1) and A(3) still need to exist with the same ID and if I understand correctly, A(1) A(2) and A(3) can be relaunch at an other time and need to release their settings; you don't want to have A(3) (for example) change ID to A(2).
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
|
This code is supposed to draw the bitmap/image to an HDC specified:
image->Draw(hdc);
This was code was ok, and was drawing on CView::OnDraw()
Now I want the image to be drawn as an Icon/Thumbnail to a CListBoxCtrl.. This is my code (this code was taken from the CListImageCtrl article..)
I get the HBITMAP retunred from the function, then attach it on a CBitmap and then add the CBItmap, and then the icon is supposed to appear on the ListCtrl.. But it doesn't...
the original code is like this:
<br />
IPicture* pPic;<br />
OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture,(LPVOID*)&pPic);<br />
<br />
...<br />
...<br />
...<br />
HBITMAP hPicRet = (HBITMAP)CopyImage(hPic, IMAGE_BITMAP, nWidth, nHeight , LR_COPYDELETEORG); <br />
<br />
CDC hdcSrc, hdcDst;<br />
hdcSrc.CreateCompatibleDC(NULL);<br />
hdcDst.CreateCompatibleDC(NULL);<br />
<br />
CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet);<br />
<br />
CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(hBmReturn);<br />
<br />
hdcDst.BitBlt(XDest,YDest,nDestWidth, nDestHeight, &hdcSrc,0,0,SRCCOPY); <br />
<br />
pOldBitmapImage = (HBITMAP)SelectObject(hdcDst.m_hDC,bm);<br />
<br />
return pOldBitmapImage<br />
This code was ok but I modified this code because IPicture cant handle other image formats to i use an image library..
i replace this code:
CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet);<br />
with:
hdcSrc.CreateCompatibleDC(NULL);<br />
image->Draw(hdcSrc.GetSafeHdc());<br />
T
The images doesn't appear.. I modified the code based on my understanding of CDC and Bitmaps..
Help please
"the possibilities are endles..."
|
|
|
|
|
Maverick wrote:
hdcSrc.CreateCompatibleDC(NULL);
image->Draw(hdcSrc.GetSafeHdc());
When you create a DC via CreateCompatibleDC it does not have a usable drawing surface (memory) associated with it. You have to use SelectObject to select a bitmap drawing surface into it. And be sure to restore the DC back to it's original state before deleting it.
hdcSrc.CreateCompatibleDC(NULL);
CBitmap TempBitmap;
TempBitmap.CreateCompatibleBitmap(hdcDst, image->Width(), image->Height());
CBitmap *pOldBitmap = (CBitmap *)hdcSrc.SelectObject(&TempBitmap);
image->Draw(hdcSrc.GetSafeHdc());
...
hdcSrc.SelectObject(pOldBitmap);
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
so, meaning before i draw to a CDC, it must have an attached HBITMAP first right?
tnx bro.!
"the possibilities are endless..."
|
|
|
|
|
Do I have to synchronize access to a CTypedPtrArray which is used from two different threads? Or can I just add items in one thread and delete items in the other? How can that by synchronized the easiest way. Thanks in advance for your help
Regards
Konrad
|
|
|
|
|
You may want to use a CCriticalSection to achieve synchronization.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I want to be able to, on a command, select the LAST line of text in my ViewEdit class and cut it or clear it. I have been working with
GetEditCtrl().SetSel(LineBeginning, LineEnd);
GetEditCtrl().Cut();
I am having a lot of difficulty in getting this to work correctly.
The problem I am having is selecting the last line, finding linebegining and line end.
Is there an easier way to clear or cut the last line of text?
Thanks
John
|
|
|
|
|
Hi all:
Recently I've finished the coding of a tiny function which is to specify the files(Mp3s) order (by which the one appear first can be played first in the Mp3 player, this order depending on the result of DOS command "dir").
I'm not familiar with file system, after a little research, I found that the order in which you copying file to the destination folder(Mp3 Player Destination drive) is the order that the mp3 will played. So I implemented the code according to this principle. I was excited to found I really can control which mp3 should be played first. But after a little testing I found that this principle is not running stable, It will out of order once in a while.
Finally I decided to turn to another alternative which is FDT(File Directory Table). I heard from some guys that FDT can decide the file order either but much at low level.I wish I could write to the FDT of each file such that to achieve the objective. Can anybody provide the principle of writing to FDT or totally different method to affected the file order?
really appreciated !!!
|
|
|
|
|
How do I convert a PDF file into an EMF format using Visual C++. Can anyone help.
Thanks in Advance,
fsdfsdfsdfsdfsdfsdf
|
|
|
|