Click here to Skip to main content
14,692,052 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to get disk/drive size Pin
MKC0023-Feb-10 3:28
MemberMKC0023-Feb-10 3:28 
AnswerRe: How to get disk/drive size Pin
Richard MacCutchan3-Feb-10 3:51
mveRichard MacCutchan3-Feb-10 3:51 
GeneralRe: How to get disk/drive size Pin
Adam Roderick J3-Feb-10 20:14
MemberAdam Roderick J3-Feb-10 20:14 
GeneralRe: How to get disk/drive size Pin
MKC0023-Feb-10 21:20
MemberMKC0023-Feb-10 21:20 
GeneralRe: How to get disk/drive size Pin
Richard MacCutchan3-Feb-10 23:02
mveRichard MacCutchan3-Feb-10 23:02 
AnswerRe: How to get disk/drive size Pin
Kushagra Tiwari3-Feb-10 3:57
MemberKushagra Tiwari3-Feb-10 3:57 
GeneralRe: How to get disk/drive size Pin
MKC0023-Feb-10 21:19
MemberMKC0023-Feb-10 21:19 
QuestionWriting Objects into files in binary mode Pin
Sujan Dhakal3-Feb-10 2:58
MemberSujan Dhakal3-Feb-10 2:58 
Writing Object Succeeds with the following code

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

class Data
{
public:
	string name;
	int id;
public:
	Data(){}
	Data(string n,int id){name=n;this->id=id;}
};

int main() {

	Data objdata("sujan dhakal",1);
	fstream file("c:\\test.txt",ios::out | ios::binary);
	if(file.is_open())
	{
		file.write((char*)&objdata,sizeof(Data));
		cout<<"Success";
		file.close();
	}
	else
	{
		cout<<"Error";
	}

	return 0;
}


but why reading not working

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

class Data
{
public:
string name;
int id;
public:
Data(){}
Data(string n,int id){name=n;this->id=id;}
};

int main() {

Data objdata;
fstream file("c:\\test.txt",ios::in | ios::binary);
if(file.is_open())
{
file.read((char*)&objdata,sizeof(Data));
cout<<objdata.name<<objdata.id<<endl;
cout<<"Success";
file.close();
}
else
{
cout<<"Error";
}

return 0;
}

help me
AnswerRe: Writing Objects into files in binary mode Pin
Cedric Moonen3-Feb-10 3:10
MemberCedric Moonen3-Feb-10 3:10 
GeneralRe: Writing Objects into files in binary mode Pin
Sujan Dhakal3-Feb-10 3:17
MemberSujan Dhakal3-Feb-10 3:17 
AnswerRe: Writing Objects into files in binary mode Pin
CPallini3-Feb-10 3:20
mveCPallini3-Feb-10 3:20 
GeneralRe: Writing Objects into files in binary mode Pin
Sujan Dhakal3-Feb-10 3:28
MemberSujan Dhakal3-Feb-10 3:28 
QuestionUnable to paste clipboard data by sending WM_PASTE message Pin
lazy_panther3-Feb-10 2:30
Memberlazy_panther3-Feb-10 2:30 
AnswerRe: Unable to paste clipboard data by sending WM_PASTE message Pin
Iain Clarke, Warrior Programmer3-Feb-10 4:45
MemberIain Clarke, Warrior Programmer3-Feb-10 4:45 
AnswerRe: Unable to paste clipboard data by sending WM_PASTE message Pin
LunaticFringe3-Feb-10 4:48
MemberLunaticFringe3-Feb-10 4:48 
QuestionRe: Unable to paste clipboard data by sending WM_PASTE message [modified] Pin
lazy_panther3-Feb-10 17:35
Memberlazy_panther3-Feb-10 17:35 
AnswerRe: Unable to paste clipboard data by sending WM_PASTE message Pin
LunaticFringe3-Feb-10 19:44
MemberLunaticFringe3-Feb-10 19:44 
GeneralRe: Unable to paste clipboard data by sending WM_PASTE message Pin
lazy_panther4-Feb-10 2:50
Memberlazy_panther4-Feb-10 2:50 
GeneralRe: Unable to paste clipboard data by sending WM_PASTE message Pin
LunaticFringe4-Feb-10 14:32
MemberLunaticFringe4-Feb-10 14:32 
QuestionTroublesome Handling of Files in C++ Pin
Sujan Dhakal3-Feb-10 2:29
MemberSujan Dhakal3-Feb-10 2:29 
AnswerRe: Troublesome Handling of Files in C++ Pin
CPallini3-Feb-10 2:37
mveCPallini3-Feb-10 2:37 
AnswerRe: Troublesome Handling of Files in C++ [modified] Pin
Stuart Dootson3-Feb-10 2:46
professionalStuart Dootson3-Feb-10 2:46 
GeneralRe: Troublesome Handling of Files in C++ Pin
CPallini3-Feb-10 2:54
mveCPallini3-Feb-10 2:54 
GeneralRe: Troublesome Handling of Files in C++ Pin
Stuart Dootson3-Feb-10 3:28
professionalStuart Dootson3-Feb-10 3:28 
AnswerRe: Troublesome Handling of Files in C++ Pin
Raj Indian3-Feb-10 23:00
MemberRaj Indian3-Feb-10 23:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.