Trouble opening saved arrays

I am having a lot of trouble saving and then opening arrays

Save by:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
string bucket, mop, broom;
bucket="bucket";
mop="mop";
broom="broom";
string items [3] = {bucket, mop, broom};
char filename[20]="item_list";
ofstream Student(filename, ios::out);
Student << items;
cout << items [0];
system("PAUSE");
return 0;
}

And then try to open by:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
char items [40];
ifstream itemslist("item_list");
itemslist >> items;
cout << items [0] << " " << items [1] << " " << items [2];
system("PAUSE");
return 0;
}

and it returns 0 x 2 (noteable part of the string assigned to an array that hasn't been defined yet)
Problem with saving, following writes the address of items to the file.
Student << items;
You want (assuming one student per line)
Student << items[0] << endl << items[1] << endl << items[2] << endl;

For reading you need to change
1
2
3
char items[40];
to 
string items[3];

and
1
2
3
itemslist >> items;
to
itemslist >> items[0] >> items[1] >> items[2];
Awesome! well... mostly. Its working on some of my programs but not on others.
Topic archived. No new replies allowed.