|
|
C_Zealot wrote: I am stuck right here. Am I supposed to check the return value of ifstream? Or am I supposed to employ a member function of ifstream, but which one?
You need to check if ifstream in is a valid stream. It's an object so you need to call it's is_open() , good() , or bad() function.
if(!in.is_open())
cerr << "File didn't open correctly!";
if(in.bad())
cerr << "File bad bit is set!";
if(!in.good())
cerr << "File is not good for use!";
You can also just do:
if(!in)
cerr << "File didn't open correctly!";
Which I believe checks if the file opened, but does NOT check if the any of the bad bits are set (could be wrong).
I recommend the in.good() approach, personally, as it checks everything for you.
My favorite pure C++ reference site. Goes great alongside MSDN.
http://www.cplusplus.com/reference/iostream/ifstream/[^]
Good luck
-- modified at 14:41 Wednesday 23rd May, 2007
|
|
|
|
|
|
I'm trying to make a program that will loop the end where it takes in all the information in the "LIBRARIANSHAVE347CATS.DAT" and if the book has more then 200 pages it outputs the information to a different file called "bigbook.dat"
This is my code so far:
struct card_catalogue
{
float dewey;<br />
string title;<br />
string author;<br />
int released;<br />
int num_pages;<br />
enum typeofbook {fiction = 1, nonfiction, reference, pond};<br />
};<br />
<br />
int main()<br />
{ <br />
card_catalogue books;<br />
ofstream outfile;<br />
int i;<br />
bool rerun = 1;<br />
ifstream infile;<br />
ofstream outfilebb;<br />
<br />
outfile.open("LIBRARIANSHAVE347CATS.DAT",ios::out);<br />
while(rerun)<br />
{<br />
cout<< "Enter the Dewey Decimal Number please: ";<br />
cin>> books.dewey;<br />
cout<< "Enter the Title of the book please: ";<br />
getline(cin, books.title);<br />
cin.ignore(80, '\n');<br />
cout<< "Enter the Author of the book please: ";<br />
getline(cin, books.author);<br />
cout<< "Enter the Year of Release please: ";<br />
cin>> books.released;<br />
cout<< "Enter the Number of Pages please: ";<br />
cin>> books.num_pages;<br />
cout<< "<-----Type----->"<<endl; <br />
cout<<"1 - Fiction" <<endl<br />
<<"2 - Non-Fiction" <<endl<br />
<<"3 - Reference" <<endl<br />
<<"4 - pond"<< endl;<br />
cout << "Enter the type: ";<br />
cin >> i;<br />
<br />
<br />
if(i == 1)<br />
{<br />
cout << "You chose Fiction\n";<br />
}<br />
if(i == 2)<br />
{<br />
cout << "You chose Non-Ficiton\n";<br />
}<br />
if(i == 3)<br />
{<br />
cout << "You chose Reference\n";<br />
}<br />
if(i == 4)<br />
{<br />
cout << "You chose Pond\n";<br />
} <br />
<br />
<br />
<br />
if(outfile)<br />
{<br />
outfile << books.dewey;<br />
outfile << books.title << endl;<br />
outfile << books.author << endl;<br />
outfile << books.released << endl;<br />
outfile << books.num_pages << endl;<br />
outfile << i << endl;<br />
}<br />
else<br />
{<br />
cout << "An error occurred while opening the file. \n";<br />
}<br />
cout << "Do you want to run this program again? Press 1 if so, 0 if no." << endl;<br />
cin >> rerun;<br />
}<br />
outfile.close();<br />
<br />
<br />
<br />
<br />
infile.open("LIBRARIANSHAVE347CATS.DAT",ios::in);<br />
outfilebb.open("Bigbook.dat",ios::app);<br />
while(infile)<br />
{<br />
infile >> books.dewey;<br />
infile >> books.title >> endl;<br />
infile >> books.author >> endl;<br />
infile >> books.released >> endl;<br />
infile >> books.num_pages >> endl;<br />
infile >> i >> endl;<br />
<br />
<br />
if (books.num_pages > 200)<br />
{<br />
if(outfilebb)<br />
{<br />
outfilebb << books.dewey;<br />
outfilebb << books.title << endl;<br />
outfilebb << books.author << endl;<br />
outfilebb << books.released << endl;<br />
outfilebb << books.num_pages << endl;<br />
outfilebb << i << endl <<endl;<br />
<br />
}<br />
}<br />
}<br />
outfile.close();<br />
infile.close(); <br />
return 0;<br />
}
|
|
|
|
|
Ok, so what exactly is the problem?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
Can I change the CREATESTRUCT& cs without calling PreCreateWindow function in the ChildFrame and assign it to the window class procedure AfxRegisterWndClass()
Prithaa
|
|
|
|
|
What does mean "without calling PreCreateWindow"? The window class should be registered before the window gets created. To modify a window class, an ideal place is PreCreateWindow. If the window has already been created then you still may change separate attributes [of the window class] by using SetWindowLong, SetWindowLongPtr, SetClassLong..
--
=====
Arman
|
|
|
|
|
prithaa wrote: Can I change the CREATESTRUCT& cs without calling PreCreateWindow function in the ChildFrame
Do you mean without calling the base class PreCreateWindow()?
If so, then yes. If you want to use a different window class than the default MFC class then
you'll want to call AfxRegisterWndClass() sometime before you create the window (I personally
do this in the constructor). In your PreCreateWindow() override, set the class name in the
createstruct to the name of the class you registered.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
hello,
Thanks for all your replies.
I mainly want to change the menu of the child window for which I want to change the CREATESTRUCT& cs.hMenu.
But even if I assign cs.hMenu = mynewmenu which is an object of CMenu I fail to see the new menu when the child window appears but
if I assign cs.lpszName = "my Window"; then the title changes of the child window.
I don't know why the menu does not take effect but the title of the window changes
Thanks
Pritha
|
|
|
|
|
Can child windows have a menu? According to the docs, the HMENU is an integer ID when the
window is a child.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi.
I have developed a program in Visual C++, MFC.
When I finished I ordered all the .h and .cpp files in folders, and then changed all the includes so that it could work fine.
It works, there is no error. but now when I open the class wizard it is empty. I think that it may be looking for the files in the old place. So, how can I say to the class wizard that now all the files are in another folder? Thanks.
|
|
|
|
|
Class wizard information is saved in a *.clw file. Delete this file and open class wizard again. It will ask you to rebuild class wizard info from source file, say yes. You will be able to select all your files once again.
|
|
|
|
|
Gosh!!! Thanks a lot!! I love you!!!
|
|
|
|
|
Already running into some issues, like not being able to add member variables of control types to controls in an MFC dialog app, but hoping a patch is available for VS2005 (or Vista?) to fix this?????
Are there any other issues I need to be aware of - the new IDE looks very nice, and it seems to compile and run under Vista but don't want to waste too much time making something work if there are going to be serious problems ahead.
cheers
Lee
|
|
|
|
|
|
That seems to have done something (installed SP1 and then the Vista update), but still don't seem to be able to properly/easily add member control variables to controls on dialogs like I used to with the class wizard. Even if I right click on the class view and Add variable, though I can now tick the control variable box, nothing is showing up in the drop down list for control IDs etc, and basically everything is empty - should this be working?
|
|
|
|
|
can anyone help please?
|
|
|
|
|
I had Buil my source code and be error like follow,
Please help Me....to solve them (my mail:thoyib.bustomi@iaodt.com) :
1>Compiling resources...
1>Linking...
1>LINK : warning LNK4068: /MACHINE not specified; defaulting to X86
1>.\maxcust.def(3) : warning LNK4017: DESCRIPTION statement not supported for the target platform; ignored
1>.\maxcust.def(4) : warning LNK4017: EXETYPE statement not supported for the target platform; ignored
1> Creating library .\Debug/maxcust.lib and object .\Debug/maxcust.exp
1>mc200.obj : error LNK2019: unresolved external symbol __imp__wsprintfA referenced in function _GetText
1>mc200.obj : error LNK2019: unresolved external symbol __imp__GetWindowTextA@12 referenced in function _A_FindItemNum
1>mc300.obj : error LNK2001: unresolved external symbol __imp__GetWindowTextA@12
1>mc400.obj : error LNK2001: unresolved external symbol __imp__GetWindowTextA@12
1>mc200.obj : error LNK2019: unresolved external symbol __imp__SetWindowTextA@8 referenced in function _A_CompatibleRef
1>mc300.obj : error LNK2001: unresolved external symbol __imp__SetWindowTextA@8
1>mc400.obj : error LNK2001: unresolved external symbol __imp__SetWindowTextA@8
1>mc200.obj : error LNK2019: unresolved external symbol __imp__SetFocus@4 referenced in function _A_CheckApproverRequester
1>.\Debug/maxcust.dll : fatal error LNK1120: 4 unresolved externals
1>Creating browse information file...
1>Microsoft Browse Information Maintenance Utility Version 8.00.50727
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Build log was saved at "file://c:\Developer's Kit\maxcust\Debug\BuildLog.htm"
1>maxcust - 9 error(s), 1054 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
|
|
|
|
|
add an #include to afxwin.h in your project.
But this seems weird, usually this goes automatically added to the project when creating it. What plateform are you compiling for ? CE ?
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
|
|
|
|
|
Rage wrote: add an #include to afxwin.h in your project.
If afxwin.h was missing, he would be receiving compiler errors, not linker errors.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Whats your application type and your compiler?
|
|
|
|
|
specify the user32.lib in the link tab->object/library modules of the project settings
nave
|
|
|
|
|
Hello,
I'm using this code in all the dialogs of my app:
void CTAM_BODlg::OnActivateApp(BOOL bActive, DWORD dwThreadID)
{
CDialog::OnActivateApp(bActive, dwThreadID);
#ifndef DEBUG
if (bActive == FALSE)
{
this->SendMessage(WM_CLOSE);
}
#endif
}
The thing is that it seems it don't work always, sometimes the application just don't get closed.
I cannot get the keyboard strokes and neither I can get the mouse events, the computer in which that application is installed is not a normal computer, it is a robot controller. The software on the robot allows me to launch my application, but it don't allow me to get the keystrokes as the keyboard is not a normal keyboard that they are handling in a special way. In any way, when the customer presses one defined key, automatically the robot controller computer sets the focus to the main robot application. After that point I'd like to get my application closed. And this is what it fails sometimes.
What could I check or modify in order to make it work always?
As always thank you in advance.
|
|
|
|
|
Can you debug it (not with the debugger, but with a message on a display or something, just to be sure you are indeed going through the code ?)
You could as well try the OnKillFocus handler instead.
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
|
|
|
|
|
I'm using this code in all the dialogs of my app:
In regard to this info, your call SendMessage(WM_CLOSE) is wrong. It would close the application only when 'this' is the main window pointer. Otherwise, the call closes a concrete dialog only. [Actually, you'd rather call PostMessage not SendMessage, anyway..].
Put AfxPostQuitMessage(0) instead of sending WM_CLOSE.
--
=====
Arman
|
|
|
|