|
|
|
Have you looked here?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Have you looked
Rhetorical question?
|
|
|
|
|
I got this from a computer science class and it's supposed to create a file for me. I copied it directly, and it doesn't seem to work as nothing shows up in the file. What's wrong? Thanks
#include <fstream.h>
#include<iostream.h>
struct rec
{
char name[25];
int age;
float wt;
};
int main()
{
rec stdrec[8] = {{"helen", 10, 10}, {"julie", 20,20}, {"lena",30,30},{"alan", 40, 40}, {"annie", 50,50},
{"may", 60, 60}, {"lee", 70, 70}, {"ed", 80,80}};
fstream fout("final.dat", ios::out||ios::binary);
int i;
for(i=0; i<8; i++)
{
fout.write((char*)&stdrec[i], sizeof(stdrec[i]));
cout<
|
|
|
|
|
Fixed line in bold:
#include <iostream>
#include <fstream>
using namespace std;
struct rec
{
char name[25];
int age;
float wt;
};
int main()
{
rec stdrec[8] = { {"helen", 10, 10},
{"julie", 20, 20},
{"lena", 30, 30},
{"alan", 40, 40},
{"annie", 50, 50},
{"may", 60, 60},
{"lee", 70, 70},
{"ed", 80,80}
};
fstream fout("final.dat", ios::out | ios::binary);
for(int i=0; i<8; i++)
{
fout.write((char*)&stdrec[i], sizeof(stdrec[i]));
cout << stdrec[i].name << "\t"
<< stdrec[i].age << "\t"
<< stdrec[i].wt <<endl;
}
return 0;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks, I tried to run it, but the file output is weird. Is this because it's in binary mode? Sorry I'm still new to programming.
|
|
|
|
|
liuphil1 wrote: ...the file output is weird.
Define "weird."
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
It's all on one line, and there's a lot of strange characters that were not in the initializations.
|
|
|
|
|
Its a binary file. Reading it in Notepad, Wordpad, or any other text editor will show you lots of weird characters.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
You won't be able to read the file. It is in binary. If you want to look at it, open it up in a hex editor to verify its contents. Otherwise, write a method to read in the data in a similar fashion to the way it is written and then print it to the screen:
fstream fin("final.dat", ios::in | ios::binary);
while (!fin.eof())
{
rec r;
fin.read((char*)&r, sizeof(rec));
cout << r.name << "\t"
<< r.age << "\t"
<< r.wt <<endl;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
i create a dialog based application
it consists of two from class
form1 and form2
i can display form1 like this
CDialog form1(IDD_FORM1)
form1.DoModal();
if i try to display form2 from
form1 by OnOK()method like this
CDialog form2(IDD_FORM2)
form2.DoModal();
IT IS NOT WORKING
HOW CAN I DO IT
janan
|
|
|
|
|
ningthemcha wrote: IT IS NOT WORKING
what happens ?
can you post the relevant parts of your code ?
|
|
|
|
|
See MSDN article Q138681.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I'm guessing that Form1 is your main dialog for your application? That being the case, when you click "OK", it ends up exiting the program. So even if you spawn another dialog, the main thread is exiting.
Use a different button, or don't call CDialog::OnOK in your OnOK handler ... or don't use Form1 for your main dialog.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Do you get error?if yes what if no whats happen?
|
|
|
|
|
i made a program using flexgrid ActiveX control and when i run and call a function from the flexgrid class i got a debug assertion failed mesaage
|
|
|
|
|
|
Use your debugger to see where your program crashes.
And if you want more chances to get an answer you have to provide a lot more informations (but still, use your debugger and if you are stuck, THEN post informations that comes from your debugger).
|
|
|
|
|
when calling msflexgrid::clear() for example the program fails in this line
ASSERT(m_pCtrlSite != NULL); in the vs/src/WINOCC.cpp file
|
|
|
|
|
Are you calling AfxEnableOleAutomation() or CoInitialize() in your InitInstance function?
Usually you get those types of assertions when you haven't initialized COM.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
how can i initialize COM? and what's the declaration for these two functions?
|
|
|
|
|
identity_85 wrote: how can i initialize COM?
By using one of the two functions that Zac mentioned.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: identity_85 wrote:
how can i initialize COM?
By using one of the two functions that Zac mentioned.
This is about the time where I would tell him to take his hands off the keyboard, go to Barnes and Noble, buy any Intro to C++ book and any Intro to COM book ... and not to touch the keyboard again until both have been read and understood ... *sigh*
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: This is about the time where I would tell him to...go to Barnes and Noble...
Be sure to include directions.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|