I have used the above code to write the class instanc to a file "Text.txt"...
But it seems that "f.write((char*)&c, sizeof(CLS));" is not working properly with string. The data can easily be written using stream object!! Please someone tell me what's the problem and how can I correct it 'coz I require this type of codes for my Project also!!
void main()
{
string name;
fstream f;
f.open("D:\\Text.txt", ios::in);
f.read((char*)&c, sizeof(CLS));
cout<<"Name: "<<c.name.c_str();
cout<<"\nSize: "<<c.name.size();
f.close();
getch();
}
When I tried to read the data on the file...., it gave an error "Thread stopped...violation.."
Thanks....
But What if I have a class having variables of other data types also... and I want to write them all on the file in one go!! Aren't you telling me to write and read them all one by one in the program code, are you??
Hey, is this possible to convert
int 45 to char "45"
or char "100" to int!!! (I think that's not possible)
Just asking for a knowledge..... I know about the conversions by subtracting 48..... but that works only for single digit only. Suppose if your conversion further(after converting to nos.) requires normal arithmetic operations!!
> I know about the conversions by subtracting 48..... but that works only for single digit only.
It only works if in the encoding used for the execution character set, character '0' has a value of 48. It is at best a non-portable construct that would work for the culture that you belong to, with its most commonly used implementations.
> is this possible to convert int 45 to char "45" or char "100" to int!!!