|
Now I feel bad for my reply which appears harsher than I intended it to be. Sorry.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi,
Thanks again for your reply.
This is not for a school project. I'm just playing around with "classes" and wanted to experiment with sharing the instances (fields) between classes.
I replied to Christian and mentioned that I will probably try using "classes with inheritance". <class_specifier> <derived_class_name> : < base_class_name { additional members> };
Unfortunately some of the C++ books I have been reading, do not show you "interaction" between different classes at the beginning.
The other things I have seem is to make the instances public BUT it kinds of defects the beauty of C++.
Thanks again and please don't feel bad. I know of many people who want others to do everything for them.
Regards,
Reni
|
|
|
|
|
Hey guys,
I'm having trouble reading an integer from a text file.
for example I have the following stored in a text file
------------ beginning of file------------excluding this line
H
88
------------ end of file------------excluding this line
and there are no spaces after any of the above words, each word is stored in one line.
I have an ifstream object that reads
char charVar;
int intVar;
inFile.read(reinterpret_cast<char*>(&charVar),sizeof(char));
cout <<"char value is : "<<charvar ;
infile.read(reinterpret_cast<char*="">(intVar),sizeof(int));
cout <<"int Var is : "<
|
|
|
|
|
The number is stored in the file as text, so you have to read it in as text then transalte it into a number using atoi() ect.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Per MSDN, read() reads the number of bytes specified by the second parameter. In this case, it reads 1 byte into charVar , but leaves the CRLF characters in the stream for the next call to read() . I think you need to use getline() instead.
LudaLuda wrote:
and I have to use the ios::binay method to open the file,
Why? From what you've shown, binary mode is not necessary.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
okey guys I got that part to work.
Now I have another problem.
how do I move the pointer so that it points to the beginning of the next record location in the file. I have several records in the file.
|
|
|
|
|
seekp(...);
seekg(...);
Maxwell Chen
|
|
|
|
|
LudaLuda wrote:
how do I move the pointer so that it points to the beginning of the next record location in the file. I have several records in the file.
That all depends on what a "record" is.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I have the following code:
TCHAR * ptszVersionInfo = _T(""); //Executes OK
ptszVersionInfo = new TCHAR[10]; //Executes OK
delete ptszVersionInfo; //Executes OK
ptszVersionInfo = _T("Anton"); //Executes OK
delete ptszVersionInfo; //Weird erro. From debug assert.It basically says there is an error with _CrtIsValidHeapPointer.
Now how come. (I am not very good with string allocation ).
|
|
|
|
|
HAHAHA_NEXT wrote:
_T("Anton"); is a pointer to STATIC memory, u can't free it!
HAHAHA_NEXT wrote:
ptszVersionInfo = new TCHAR[10]; //Executes OK
delete ptszVersionInfo; //Executes OK this would rather be delete [] ptszVersionInfo;
Don't try it, just do it!
|
|
|
|
|
Is there a way i can allocate _T("Anton") Into a dynamic memory ? because my code is all mixed up. (I allocate the string using both methods).
|
|
|
|
|
HAHAHA_NEXT wrote:
Is there a way i can allocate _T("Anton") Into a dynamic memory ?
This does not quite make sense, but I think what you want is:
TCHAR *p = new TCHAR[6];
_tcscpy(p, _T("Anton"));
...
delete [] p;
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Ths. It is exactly what i needed. The reason for this kind of weird stuff is because i can allocate the same string 2 ways:
the first is
p = "Anton"
and the second is
<br />
p = new TCHAR[6];<br />
_stprintf(p, ....)<br />
This will avoid me having different variable and one clean delete statement .
|
|
|
|
|
HAHAHA_NEXT wrote:
...
delete ptszVersionInfo; //Executes OK
ptszVersionInfo = _T("Anton"); //Executes OK
delete ptszVersionInfo;
Two problems:
1) You are using ptszVersionInfo after you've done a delete on it.
2) You are doing a second delete on a ptr that you've already done a delete on.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I have a derived Dialog class - CGeneralStatus that has a CString variable. If I set the string before I create the CGeneralStatus dialog it is displayed OK. When I set this string to different value the value in the window does not get changed. Even if I close and reopen the dialog window the value does not change.
Any input is greatly appreciated !
------------------------------------------------------------------------
Application code:
void CFV3TaskMonApp::OnGeneralstatus()
{
if(IsShowingGeneral())
{
HideGeneral();
}
else
{
ShowGeneral(m_pMainWnd->GetActiveWindow());
}
}
void CFV3TaskMonApp::ShowGeneral(CWnd* parent)
{
if (!::IsWindow(*m_generalStatus))
{
m_generalStatus->Create(IDD_GeneralStatus, parent);
}
m_generalStatus->GeneralChanged(); // update the string
m_generalStatus->ShowWindow(1);
}
Code snippet to update the string value before calling ShowWindow(1):
void CGeneralStatus::GeneralChanged()
{
CString out;
out.Format("%d",m_app->m_numConnections);
m_connAttempts = out;
if (::IsWindow(this->GetSafeHwnd()))
{
::PostMessage(this->GetSafeHwnd(),UWM_STATUS_UPDATEGENERAL,0,0);
}
}
|
|
|
|
|
glweid wrote:
When I set this string to different value the value in the window does not get changed.
Even though you've assigned a value to a CString variable, you did not indicate how it was being displayed. Assuming it was an edit or static control, you simply need an appropriate control variable in the dialog's declaration (e.g., CEdit m_editnumConnections ). When it comes time to display the value, simply call m_editnumConnections.SetWindowText() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
My Dialog box only has the string variable (edit control - read only) box displayed, how do you declare a CEdit variable associated with that ?
I added a CEdit m_editnumCOnnections compiled it and passed the new string value to m_editnumConnections.SetWindowText() and it cores not finding a main window handle.
Thanks !
-----------
Code snip
// Dialog Data
//{{AFX_DATA(GeneralStatus)
enum { IDD = IDD_GeneralStatus };
CString m_connAttempts;
//}}AFX_DATA
|
|
|
|
|
Anonymous wrote:
how do you declare a CEdit variable associated with that ?
ClassWizard.
Anonymous wrote:
...and it cores not finding a main window handle
What does "cores" mean in this context? Did you add the appropriate entry to DoDataExchange() ? This is something that ClassWizard would do for you.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I want to suspent my display using a shortcut... no matter if vc++ or not.
Since I've never worked with power management I don't know how.
Any suggestions?
Thx
Don't try it, just do it!
|
|
|
|
|
Alexander M. wrote:
I want to suspent my display using a shortcut...
I don't quite understand what this means.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Have you looked at the Power Management API functions. eg. SetSystemPowerState() Should do the trick.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
thx
(I'm sorry for the wrong spelling of suspend )
Don't try it, just do it!
|
|
|
|
|
How do you stop an SDI application window from being resized?
Thanks
|
|
|
|
|
I think removing the client edge style will do the trick.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Thanks, that worked, but now I have another couple of problems.
First of all I have a status bar and I cannot get rid of the gripper on that.
Secondly there is now a 1 pixel wide transparent gap around the view (where I assume the thick border would have been)
You can see what I mean at http://a.domaindlx.com/sschilachi/snooker.JPG[^]
Thanks
|
|
|
|