Well, as I see it, you have two options.
You can simply fix the code that way:
Code:
file2.getLine(info,100);
//where 100 is how much bytes are to be read and info is where to read
cout<<"Name:" << info << endl;
and so on.
another way is making it a binary file (you'll need to save it binaricly first) like that:
Code:
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
struct info{
//all of the members of the struct
char name[100];
int value;
};
int main(){
ofstream out_file("binary.bin",ios::binary|ios::trunc);
info save;
strcpy(save.name,"NAME");
save.value=10;
out_file.write((const char *)&save,sizeof(info));
}
then, after you have saved the file, load it like that:
Code:
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
struct info{
//all of the members of the struct
char name[100];
int value;
};
int main(){
ifstream in_file("binary.bin",ios::binary);
info load;
//it'll be equal to 10;
load.value=18;
in_file.read((char *)&load,sizeof(info));
cout<<"Name:"<<load.name<< endl;
cout<<"Value:"<<load.value<< endl;
}
I guess that with some small changes you will also be able to output & input c++ strings(changing variables declarations from char to string,etc).
this code was compiled using borland c++ compiler and I dont know how will it work on other compilers. give it a shot and tell me what happend.