|
no worries. I guessed you were doing this to learn, which is why I'm trying to cover some best practice stuff, so you learn how to do things *well*. Good luck
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian,
Thanks again.
I agree with you. Making the instances public in a class is kind of "ugly".
I will be testing inherited classes.
Thanks,
Reni
|
|
|
|
|
beamer_2020 wrote:
What do I have to do
How do I
The best suggestion I can give you is that you read the introductory chapters of the C++ book assigned by the instructor. If you have specific questions, you'll find the CP community will be happy to help you. But don't expect a CP member to do your homework for you.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi,
I wasn't expecting anyone to write code for me. I want to thank you for taking the time to reply.
Regards,
Reni
Renato
|
|
|
|
|
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
|
|
|
|