Nov 6, 2011 at 4:59pm UTC
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)
Nov 7, 2011 at 11:34pm UTC
Awesome! well... mostly. Its working on some of my programs but not on others.