Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with reading data through ifstream object in C++

Status
Not open for further replies.

aamiralikhoja

Member level 5
Joined
Aug 11, 2004
Messages
90
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
708
I have following problem in using c++ streams . if i use c to open text file

with fopen and read data through fscanf file is readed corectly .But if same

file is read through ifstream object i get wrong data .what is possible cause.

FILE *data;
float Fdata;
unsigned char Cdata[40];
data = fopen("c:\\data.txt");
fscanf(data,"%d",&Fdata);
for(int i = 0;i<20;i++)
fscanf(data."%d",&Cdata);
now in c++
float Fdata;
unsigned char Cdata[40];
ifstream data;
data.open("c:\\data.txt");
data >> Fdata;
for (int i = 0;i<20;i++)
data >> Cdata;

here is file fomat

103.9390 0F 0C 40 C8 33 33 53 0F 40 CD CC 0F 8C 40 0F 00 00 0F B0 40
103.9440 0F 41 9A C8 99 95 41 0F 66 66 0F 9E 41 33 0F 33 A7 0F 41 00
103.9490 42 66 66 C8 08 42 0F FF FF FF 0F FF CD 0F CC 8C 3F 0F CD CC
103.9540 CD CC 0F C8 64 41 66 66 76 0F 41 00 00 0F 84 41 0F CD CC 8C
103.9590 99 ED 0F C8 41 66 66 F6 41 0F 33 33 0F FF 41 00 0F 00 04 0F
103.9640 1E 0F 41 C8 00 00 30 41 0F 9A 99 41 0F 41 33 0F 33 53 41 0F
103.9690 41 0F 33 C8 33 D3 41 00 0F 00 DC 0F 41 CD CC 0F E4 41 0F 9A
103.9740 33 0F 33 C8 D3 40 66 0F 66 F6 40 0F CD CC 0F 0C 41 66 0F 66
103.9790 0F 00 B0 C8 41 CD CC 0F B8 41 0F 9A 99 C1 0F 41 66 0F 66 CA
103.9840 0F 0C 40 C8 33 33 53 0F 40 CD 0F CC 8C 40 0F 00 00 0F B0 40
103.9890 8C 41 9A C8 99 95 0F 41 66 66 0F 9E 41 0F 33 33 A7 0F 41 00
103.9940 42 66 0F C8 66 08 42 FF FF 0F FF FF CD 0F CC 8C 0F 3F CD CC
103.9990 CD CC 0F C8 64 41 66 66 76 0F 41 00 0F 00 84 41 0F CD CC 0F
104.0040 99 0F ED C8 41 66 66 F6 0F 41 33 33 0F FF 41 0F 00 00 04 0F
104.0090 1E 0F 41 C8 00 00 30 41 0F 9A 99 0F 41 41 33 0F 33 53 0F 41
104.0140 0F 41 33 C8 33 D3 41 0F 00 00 DC 0F 41 CD 0F CC E4 41 0F 9A
104.0190 0F 33 33 C8 D3 40 66 0F 66 F6 0F 40 CD CC 0F 0C 41 0F 66 66
104.0240 0F 00 B0 C8 41 CD 0F CC B8 41 0F 9A 99 0F C1 41 66 0F 66 CA
104.0290 CC 0C 40 C8 33 33 0F 53 40 0F CD CC 8C 0F 40 00 0F 00 B0 40
104.0340 8C 41 0F C8 9A 99 95 41 66 0F 66 9E 0F 41 33 33 0F A7 41 0F
104.0390 42 66 0F C8 66 08 42 FF FF 0F FF FF 0F CD CC 8C 0F 3F CD 0F
104.0440 CD 0F CC C8 64 41 66 66 0F 76 41 00 0F 00 84 0F 41 CD CC 0F
104.0490 99 0F ED C8 41 66 66 F6 0F 41 33 0F 33 FF 41 0F 00 00 0F 04
104.0540 0F 1E 41 C8 00 00 30 0F 41 9A 99 0F 41 41 0F 33 33 53 0F 41
104.0590 0F 41 33 C8 33 D3 41 0F 00 00 0F DC 41 CD 0F CC E4 0F 41 9A
104.0640 40 33 33 C8 D3 40 0F 66 66 F6 0F 40 CD 0F CC 0C 41 0F 66 66
104.0690 00 00 0F C8 B0 41 CD CC B8 0F 41 9A 99 0F C1 41 0F 66 66 CA
104.0740 CC 0C 0F C8 40 33 33 53 40 0F CD CC 0F 8C 40 00 0F 00 B0 0F
104.0790 8C 41 0F C8 9A 99 95 41 66 0F 66 9E 0F 41 33 0F 33 A7 41 0F
104.0840 42 0F 66 C8 66 08 42 FF 0F FF FF FF 0F CD CC 0F 8C 3F 0F CD
104.0890 CD 0F CC C8 64 41 66 66 0F 76 41 0F 00 00 84 0F 41 CD 0F CC
104.0940 0F 99 ED C8 41 66 66 0F F6 41 33 0F 33 FF 0F 41 00 00 0F 04
104.0990 0F 1E 41 C8 00 00 30 0F 41 9A 0F 99 41 41 0F 33 33 0F 53 41
104.1040 CA 41 33 C8 33 D3 0F 41 00 00 0F DC 41 0F CD CC E4 0F 41 9A
104.1090 40 33 0F C8 33 D3 40 66 66 0F F6 40 CD 0F CC 0C 0F 41 66 66
104.1140 00 00 0F C8 B0 41 CD CC B8 0F 41 9A 0F 99 C1 41 0F 66 66 0F
104.1190 CC 0F 0C C8 40 33 33 53 0F 40 CD CC 0F 8C 40 0F 00 00 B0 0F
104.1240 8C 0F 41 C8 9A 99 95 41 0F 66 66 0F 9E 41 33 0F 33 A7 0F 41
104.1290 42 0F 66 C8 66 08 42 FF 0F FF FF 0F FF CD 0F CC 8C 3F 0F CD
104.1340 0F CD CC C8 64 41 66 0F 66 76 41 0F 00 00 0F 84 41 0F CD CC
104.1390 0F 99 ED C8 41 66 66 0F F6 41 0F 33 33 FF 0F 41 00 0F 00 04
104.1440 66 1E 41 C8 00 00 0F 30 41 9A 0F 99 41 0F 41 33 33 0F 53 41
104.1490 CA 41 0F C8 33 33 D3 41 00 0F 00 DC 41 0F CD CC 0F E4 41 9A
104.1540 40 33 0F C8 33 D3 40 66 66 0F F6 40 0F CD CC 0C 0F 41 66 0F
104.1590 00 0F 00 C8 B0 41 CD CC 0F B8 41 9A 0F 99 C1 0F 41 66 66 0F
104.1640 CC 0F 0C C8 40 33 33 53 0F 40 CD 0F CC 8C 40 0F 00 00 0F B0
104.1690 8C 0F 41 C8 9A 99 95 0F 41 66 66 0F 9E 41 0F 33 33 A7 0F 41
104.1740 0F 42 66 C8 66 08 42 0F FF FF 0F FF FF CD 0F CC 8C 0F 3F CD
104.1790 0F CD CC C8 64 41 66 0F 66 76 0F 41 00 0F 00 84 41 0F CD CC
104.1840 9A 99 ED C8 41 66 0F 66 F6 41 0F 33 33 0F FF 41 0F 00 00 04
104.1890 66 1E 0F C8 41 00 00 30 41 0F 9A 99 41 0F 41 33 0F 33 53 41
104.1940 CA 41 0F C8 33 33 D3 41 00 0F 00 DC 0F 41 CD CC 0F E4 41 0F
104.1990 40 0F 33 C8 33 D3 40 66 0F 66 F6 40 0F CD CC 0F 0C 41 66 0F
104.2040 00 0F 00 C8 B0 41 CD CC 0F B8 41 0F 9A 99 C1 0F 41 66 0F 66
104.2090 0F CC 0C C8 40 33 33 0F 53 40 CD 0F CC 8C 0F 40 00 00 0F B0
104.2140 0F 8C 41 C8 9A 99 95 0F 41 66 0F 66 9E 41 0F 33 33 0F A7 41
104.2190 0F 42 66 C8 66 08 0F 42 FF FF 0F FF FF 0F CD CC 8C 0F 3F CD
104.2240 41 CD CC C8 64 41 0F 66 66 76 0F 41 00 0F 00 84 0F 41 CD CC
104.2290 9A 99 0F C8 ED 41 66 66 F6 0F 41 33 0F 33 FF 41 0F 00 00 0F
104.2340 66 1E 0F C8 41 00 00 30 41 0F 9A 99 0F 41 41 33 0F 33 53 0F
104.2390 CA 0F 41 C8 33 33 D3 41 0F 00 00 DC 0F 41 CD 0F CC E4 41 0F
104.2440 40 0F 33 C8 33 D3 40 66 0F 66 F6 0F 40 CD CC 0F 0C 41 0F 66
104.2490 0F 00 00 C8 B0 41 CD 0F CC B8 41 0F 9A 99 0F C1 41 66 0F 66
104.2540 0F CC 0C C8 40 33 33 0F 53 40 0F CD CC 8C 0F 40 00 0F 00 B0
104.2590 CC 8C 41 C8 9A 99 0F 95 41 66 0F 66 9E 0F 41 33 33 0F A7 41
104.2640 04 42 0F C8 66 66 08 42 FF 0F FF FF FF 0F CD CC 0F 8C 3F CD
104.2690 41 CD 0F C8 CC 64 41 66 66 0F 76 41 0F 00 00 84 0F 41 CD 0F
104.2740 9A 99 0F C8 ED 41 66 66 0F F6 41 33 0F 33 FF 0F 41 00 00 0F
104.2790 66 0F 1E C8 41 00 00 30 0F 41 9A 99 0F 41 41 0F 33 33 0F 53
104.2840 CA 0F 41 C8 33 33 D3 41 0F 00 00 0F DC 41 CD 0F CC E4 0F 41
104.2890 0F 40 33 C8 33 D3 40 0F 66 66 F6 0F 40 CD 0F CC 0C 41 0F 66
104.2940 0F 00 00 C8 B0 41 CD 0F CC B8 0F 41 9A 99 0F C1 41 0F 66 66
104.2990 CD CC 0C C8 40 33 0F 33 53 40 0F CD CC 0F 8C 40 00 0F 00 B0
104.3040 CC 8C 0F C8 41 9A 99 95 41 0F 66 66 9E 0F 41 33 0F 33 A7 41
104.3090 04 42 0F C8 66 66 08 42 FF 0F FF FF 0F FF CD CC 0F 8C 3F 0F
104.3140 41 CD 0F C8 CC 64 41 66 0F 66 76 41 0F 00 00 0F 84 41 CD 0F
104.3190 9A 0F 99 C8 ED 41 66 66 0F F6 41 0F 33 33 FF 0F 41 00 0F 00
104.3240 66 0F 1E C8 41 00 00 30 0F 41 9A 0F 99 41 0F 41 33 33 0F 53
104.3290 0F CA 41 C8 33 33 D3 0F 41 00 00 0F DC 41 0F CD CC 0F E4 41
104.3340 0F 40 33 C8 33 D3 40 0F 66 66 0F F6 40 CD 0F CC 0C 0F 41 66
104.3390 41 00 00 C8 B0 41 0F CD CC B8 0F 41 9A 0F 99 C1 41 0F 66 66
104.3440 CD CC 0F C8 0C 40 33 33 53 0F 40 CD CC 0F 8C 40 0F 00 00 B0
104.3490 CC 8C 0F C8 41 9A 99 95 41 0F 66 66 0F 9E 41 33 0F 33 A7 0F
104.3540 04 0F 42 C8 66 66 08 42 0F FF FF FF 0F FF CD 0F CC 8C 3F 0F
104.3590 41 0F CD C8 CC 64 41 66 0F 66 76 0F 41 00 00 0F 84 41 0F CD
104.3640 9A 0F 99 C8 ED 41 66 0F 66 F6 41 0F 33 33 0F FF 41 00 0F 00
104.3690 0F 66 1E C8 41 00 00 0F 30 41 0F 9A 99 41 0F 41 33 0F 33 53
104.3740 0F CA 41 C8 33 33 D3 0F 41 00 0F 00 DC 0F 41 CD CC 0F E4 41
104.3790 B0 40 33 C8 33 D3 0F 40 66 66 0F F6 40 0F CD CC 0F 0C 41 66
104.3840 41 00 0F C8 00 B0 41 CD CC 0F B8 41 9A 0F 99 C1 0F 41 66 66
104.3890 CD CC 0F C8 0C 40 33 33 53 0F 40 CD 0F CC 8C 40 0F 00 00 0F
104.3940 CC 0F 8C C8 41 9A 99 95 0F 41 66 66 0F 9E 41 0F 33 33 A7 0F
104.3990 04 0F 42 C8 66 66 08 42 0F FF FF 0F FF FF CD 0F CC 8C 0F 3F
104.4040 0F 41 CD C8 CC 64 41 0F 66 66 76 0F 41 00 0F 00 84 41 0F CD
104.4090 0F 9A 99 C8 ED 41 66 0F 66 F6 0F 41 33 33 0F FF 41 0F 00 00
104.4140 0F 66 1E C8 41 00 0F 00 30 41 0F 9A 99 0F 41 41 33 0F 33 53
104.4190 66 CA 41 C8 33 33 0F D3 41 0F 00 00 DC 0F 41 CD 0F CC E4 41
104.4240 B0 40 0F C8 33 33 D3 40 66 0F 66 F6 0F 40 CD CC 0F 0C 41 0F
104.4290 41 00 0F C8 00 B0 41 CD CC 0F B8 41 0F 9A 99 0F C1 41 66 0F
104.4340 CD 0F CC C8 0C 40 33 33 0F 53 40 CD 0F CC 8C 0F 40 00 0F 00
104.4390 CC 0F 8C C8 41 9A 99 95 0F 41 66 0F 66 9E 41 0F 33 33 0F A7
104.4440 0F 04 42 C8 66 66 08 0F 42 FF FF 0F FF FF 0F CD CC 8C 0F 3F
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top