Click here to Skip to main content
15,905,875 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Access Violation CwinThread::CreateThread Pin
ForNow4-Aug-13 6:23
ForNow4-Aug-13 6:23 
AnswerRe: Access Violation CwinThread::CreateThread Pin
Erudite_Eric5-Aug-13 22:46
Erudite_Eric5-Aug-13 22:46 
GeneralRe: Access Violation CwinThread::CreateThread Pin
ForNow6-Aug-13 1:21
ForNow6-Aug-13 1:21 
GeneralRe: Access Violation CwinThread::CreateThread Pin
Joe Woodbury9-Aug-13 11:12
professionalJoe Woodbury9-Aug-13 11:12 
GeneralRe: Access Violation CwinThread::CreateThread Pin
Erudite_Eric16-Aug-13 23:04
Erudite_Eric16-Aug-13 23:04 
AnswerRe: Access Violation CwinThread::CreateThread Pin
Stephen Hewitt7-Aug-13 20:55
Stephen Hewitt7-Aug-13 20:55 
AnswerRe: Access Violation CwinThread::CreateThread Pin
pasztorpisti17-Aug-13 4:47
pasztorpisti17-Aug-13 4:47 
QuestionUsing stream_traits for file io serialization question Pin
EQ Learner3-Aug-13 12:03
EQ Learner3-Aug-13 12:03 
I need a template function that takes a stream_type and a data type as template parameters in a function. The purpose for this template function is to either read or write data to a file (binary or text format). I define an stream_traits and its io traits specializations as following:

XML
template <typename T>
struct iostream_traits
{
    typedef T       stream_type;
};

template<>
struct iostream_traits <std::ofstream>
{
    typedef std::ofstream       stream_type;

    static const bool _bSaving = true;
    static const bool _bLoading = false;
};


template<>
struct iostream_traits <std::ifstream>
{
    typedef std::ifstream       stream_type;

    static const bool _bSaving = false;
    static const bool _bLoading = true;
};



My template function for read or write is defined as:

C++
template<typename STREAM_T, typename T>
void SerializeElement_IO(STREAM_T &ios, T &t, bool bBinary, char cDelimiter/* = ' '*/)
{
	if (iostream_traits<STREAM_T>::_bSaving)
	{
		if (bBinary) ios.write(reinterpret_cast<char *>(&t), sizeof(t)); // Binary file format
		else
		{
			if (cDelimiter == ' ')	ios << t << " ";								// Text file format
			else if (cDelimiter == '\n')	ios << t << std::endl;	
			else ios << t;	
		}
	}
	else
	{
		if (bBinary) ios.read(reinterpret_cast<char *>(&t), sizeof(t));
		else ios >> t;
	}
}




However, if I make a call to this template function in a program:

int a = 10;
C#
std::ofstream ofs("DataFile");
   SerializeElement_IO(ofs, a, true, ' ');


I got compile errors as

error C2039: 'read' : is not a member of 'std::basic_ofstream<_Elem,_Traits>'
error C3767: '>>': candidate function(s) not accessible

I am sure I have included necessary headers for the program.

I just couldn't understand why the errors are related to read or << operator while an std::ofstream object is passed to the template function.

Is there any way to implement this using traits technique?

modified 3-Aug-13 18:09pm.

AnswerRe: Using stream_traits for file io serialization question Pin
«_Superman_»4-Aug-13 20:22
professional«_Superman_»4-Aug-13 20:22 
QuestionHow to find the shortest path between two nodes in a undigraph and it should via several given nodes? Pin
ahuzhangbo2-Aug-13 18:53
ahuzhangbo2-Aug-13 18:53 
AnswerRe: How to find the shortest path between two nodes in a undigraph and it should via several given nodes? Pin
Richard MacCutchan2-Aug-13 21:51
mveRichard MacCutchan2-Aug-13 21:51 
AnswerRe: How to find the shortest path between two nodes in a undigraph and it should via several given nodes? Pin
Erudite_Eric3-Aug-13 3:23
Erudite_Eric3-Aug-13 3:23 
QuestionMFC FeaturePack application is not running in client PC. Pin
Anu_Bala1-Aug-13 20:19
Anu_Bala1-Aug-13 20:19 
AnswerRe: MFC FeaturePack application is not running in client PC. Pin
Richard MacCutchan1-Aug-13 20:24
mveRichard MacCutchan1-Aug-13 20:24 
GeneralRe: MFC FeaturePack application is not running in client PC. Pin
Anu_Bala1-Aug-13 21:28
Anu_Bala1-Aug-13 21:28 
GeneralRe: MFC FeaturePack application is not running in client PC. Pin
Richard MacCutchan1-Aug-13 21:57
mveRichard MacCutchan1-Aug-13 21:57 
GeneralRe: MFC FeaturePack application is not running in client PC. Pin
Anu_Bala1-Aug-13 22:08
Anu_Bala1-Aug-13 22:08 
QuestionRe: MFC FeaturePack application is not running in client PC. Pin
Richard MacCutchan1-Aug-13 22:02
mveRichard MacCutchan1-Aug-13 22:02 
AnswerRe: MFC FeaturePack application is not running in client PC. Pin
Argonia2-Aug-13 3:25
professionalArgonia2-Aug-13 3:25 
AnswerRe: MFC FeaturePack application is not running in client PC. Pin
«_Superman_»4-Aug-13 20:13
professional«_Superman_»4-Aug-13 20:13 
QuestionHow to store and retrieve data from database via internet using VC++2008 Pin
shanmugarajaa1-Aug-13 18:46
shanmugarajaa1-Aug-13 18:46 
AnswerRe: How to store and retrieve data from database via internet using VC++2008 Pin
Richard MacCutchan1-Aug-13 20:23
mveRichard MacCutchan1-Aug-13 20:23 
GeneralRe: How to store and retrieve data from database via internet using VC++2008 Pin
shanmugarajaa1-Aug-13 20:29
shanmugarajaa1-Aug-13 20:29 
GeneralRe: How to store and retrieve data from database via internet using VC++2008 Pin
Richard MacCutchan1-Aug-13 21:11
mveRichard MacCutchan1-Aug-13 21:11 
GeneralRe: How to store and retrieve data from database via internet using VC++2008 Pin
shanmugarajaa1-Aug-13 22:12
shanmugarajaa1-Aug-13 22:12 

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.