This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / C++ I can not read .DAT file and output to screen ------- file2.read((char *)&temp, sizeof(Car)*x);
-belhuang(wendy);
2013-3-24
{1184}
(#8116284@0)
-
你的for loop是想循环x编,但你的file2.read()一次就read了sizeof(Car)*x个data,这样你相当于read了x * x个car数据,超出文件范围了吧。
-haploidus(今剩叹);
2013-3-24
(#8116296@0)
-
cancel loop. Is it right?you mean don't use loop, like below,
Car *temp = new Car[x];
file2.read((char *)&temp, sizeof(Car)*x);
cout<<temp;
Can output all car information to screen
-belhuang(wendy);
2013-3-24
{166}
(#8116368@0)
-
Help me change it. I don't have idea.How I change?
First-chance exception at 0x10306e6f (msvcp100d.dll) in file.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
Unhandled exception at 0x10306e6f (msvcp100d.dll) in file.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
//Car temp;
Car *temp = new Car[x];
cout<<"read file";
file2.read((char *)&temp, sizeof(Car));
cout<<"Car="<<temp;
-belhuang(wendy);
2013-3-24
{414}
(#8116374@0)
-
两个方案。1.
for (int i=0;i<x; i++)
{ cout<<"read file";
file2.read((char *)&temp[i++], sizeof(Car));
cout<<(i)<<"Car="<<temp;
}
2.
cout<<"read file";
file2.read((char *)temp, sizeof(Car)*x);
for (int i=0;i<x; i++) {
cout<<(i+1)<<"Car="<<temp[i];
}
-haploidus(今剩叹);
2013-3-24
{261}
(#8116380@0)
-
why output to screen ....===>? Car=00504CC0. I think still have some wrong. see content textI change to below
Car *temp = new Car[x];
cout<<"read file";
for (int i=0;i<x; i++)
{
file2.read((char *)&temp[i++], sizeof(Car));
cout<<(i)<<"Car="<<temp;
}
-------------------output---------------------------------
Number of Cars => 1
Car Model => 111
read file1Car=00504CC0
-belhuang(wendy);
2013-3-24
{310}
(#8116388@0)
-
注意指针cout<<"read file";
for (int i=0;i<x; i++)
{
file2.read((char *)&temp[i], sizeof(Car));
cout<<(i+1)<<"Car="<<temp[i];
}
-haploidus(今剩叹);
2013-3-24
{127}
(#8116402@0)
-
cout<<(i+1)<<"Car="<<temp[i];temp[i] ---- Here wrong when I compiling
-belhuang(wendy);
2013-3-24
{42}
(#8116415@0)
-
wrong sentence for cout<<.......
Pls. get help
-belhuang(wendy);
2013-3-24
(#8116418@0)
-
再帮下去,我就只能写出来,compile完了再说了,可是没环境啊。
-haploidus(今剩叹);
2013-3-24
(#8116495@0)
-
Run problem-------- do you understand
void __CLR_OR_THIS_CALL gbump(int _Off)
{ // alter current position in read buffer by _Off
*_IGcount -= _Off;
*_IGnext += _Off;
}
-belhuang(wendy);
2013-3-24
{3323}
(#8116552@0)
-
家里电脑没有visual studio。看了你的code, 你是先把pcars[i]写到文件里,在试图读文件把数据放在 temp[i]里,再输出到 cout。
作为试验,你可以在读文件前先试试
for (int i=0; i<x; i++)
cout<<pcars[i];
-haploidus(今剩叹);
2013-3-24
{171}
(#8116567@0)
-
I give you whole code
-belhuang(wendy);
2013-3-24
(#8116556@0)
-
you can download C++ software online
-belhuang(wendy);
2013-3-24
(#8116581@0)
-
哎,好人做到底吧,进内
-haploidus(今剩叹);
2013-3-24
{3074}
(#8116821@0)
-
今大虾原来是C++大拿啊。
-wincity(红卫兵);
2013-3-24
(#8116884@0)
-
不敢不敢,略知一二。
-haploidus(今剩叹);
2013-3-25
(#8117395@0)
-
You solve the problem for this time input record and output this time record information.
If I want to append record to the previous file and output all records from the files(including old and new record )? How I modify the code?
-belhuang(wendy);
2013-3-25
(#8117308@0)
-
免费帮你做整个作业,恐怕不太现实,你还得自己努力呀。你的问题其实很简单,注意用ifstream的fseek就行了。
-haploidus(今剩叹);
2013-3-25
(#8117402@0)