outpot character problem.

#define CANDY_TYPE 5


#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>

using namespace std;


struct day{
float name_of_candy[CANDY_TYPE];
};


int totalsale [CANDY_TYPE];
float totalrm [CANDY_TYPE];


int main()
{

int sale;
float total;
string name_of_candy[5];
float candyprice [5];

cout<<"This program will read from file and count total sell of candy"<<endl;
cout<<"\t Price of the candy\n"<<endl;


ifstream infiles("e://try.docx");
if (!infiles)
{
cout<<"Can't open the file"<<endl;
return 1;

}

for (int i=0;i<CANDY_TYPE;i++)

{
(infiles>>name_of_candy[i]
>>candyprice[i] );
}

infiles.close();

cout<<setw(10)<<"Candy Name"<<setw(6)<<"Price"<<endl;

for (int i=0;i<CANDY_TYPE;i++)
{
cout<<setw(10)<<name_of_candy<<setw(6)<<"RM"<<candyprice<<endl;
}


cout<<endl<<endl;













return 0;
}
this is my code.


this is my file as test.txt



Snickers 10.55
Twizzlers 22.44
KitKat 12.88
Jelly Belly 13.89
Snickers 21.22





but why my output is like that
Candy Name Price
0x6ffc00 RM0x6ffe10
0x6ffc00 RM0x6ffe10
0x6ffc00 RM0x6ffe10
0x6ffc00 RM0x6ffe10
0x6ffc00 RM0x6ffe10


Hellllpppp
I believe what you are outputting is the address where your variable is stored

besides why are you making a struct when you are not using it..

also considering you are not using tags..
here's how to use it

http://www.cplusplus.com/articles/jEywvCM9/
ifstream infiles("e://try.docx");

DOCX files contain binary metadata. Read a plaintext file.
Last edited on
.docx files are actually ZIP files with xml files inside.
Rename it to .zip and unzip it, then you can open to see.
name_of_candy is an array of string objects.

name_of_candy[i] is one of those strings

cout << name_of_candy[i];



Topic archived. No new replies allowed.