Click here to Skip to main content
15,913,335 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Help needed to check this code below... !!! Pin
PJ Arends5-Feb-06 14:36
professionalPJ Arends5-Feb-06 14:36 
GeneralRe: Help needed to check this code below... !!! Pin
amano8u5-Feb-06 14:41
amano8u5-Feb-06 14:41 
QuestionLast call for help... HEEEELP!!!! Pin
Lord Kixdemp5-Feb-06 11:03
Lord Kixdemp5-Feb-06 11:03 
AnswerRe: Last call for help... HEEEELP!!!! Pin
PJ Arends5-Feb-06 12:02
professionalPJ Arends5-Feb-06 12:02 
GeneralRe: Last call for help... HEEEELP!!!! Pin
Lord Kixdemp5-Feb-06 16:04
Lord Kixdemp5-Feb-06 16:04 
AnswerRe: Last call for help... HEEEELP!!!! Pin
Christian Graus5-Feb-06 15:23
protectorChristian Graus5-Feb-06 15:23 
GeneralRe: Last call for help... HEEEELP!!!! Pin
Jeremy Falcon5-Feb-06 17:54
professionalJeremy Falcon5-Feb-06 17:54 
GeneralRe: Last call for help... HEEEELP!!!! Pin
Stephen Hewitt5-Feb-06 18:49
Stephen Hewitt5-Feb-06 18:49 
I also prefer the C++ file handling mechanism. Here's why I think they're better then the C counter parts.

Simplicity. The following code outputs an integer, a string and a complex number. In C we would have the call different function for each type (or use something like fprintf, but then we run into type safety issues, which is my last point, and it only works for a set number of types which doesn't include complex):
#include <fstream>
#include <complex>
using namespace std;
 
int main(int argc, char* argv[])
{
     ofstream fs("C:\\out.txt");
 
     fs << 1 << endl;
     fs << "Hello" << endl;
 
     complex<int> ComplexNumber(1,2);
     fs << "This is a complex number: " << ComplexNumber << endl;
 
     return 0;
}


Extensibility. We can extend the mechanism and when done exactly the same syntax works with our own types:
#include <iostream>
#include <string>
using namespace std;
 
// My type
struct MyData
{
     MyData(const char* pName, int Age): m_Name(pName), m_Age(Age) {}
     string m_Name;
     int m_Age;
};
 
ostream& operator<<(ostream& stm, const MyData& data)
{
     stm << "Name: " << data.m_Name << " (" << data.m_Age << ")";
     return stm;
}
 
int main(int argc, char* argv[])
{
     MyData Person("Bob", 20);
     cout << Person << endl;
 
     return 0;
}


And lastly, type safety. No fprintf evil which result if the type and the format string don't match.



Steve
GeneralRe: Last call for help... HEEEELP!!!! Pin
PJ Arends5-Feb-06 18:51
professionalPJ Arends5-Feb-06 18:51 
GeneralRe: Last call for help... HEEEELP!!!! Pin
Christian Graus6-Feb-06 9:00
protectorChristian Graus6-Feb-06 9:00 
GeneralRe: Last call for help... HEEEELP!!!! Pin
Christian Graus6-Feb-06 9:01
protectorChristian Graus6-Feb-06 9:01 
AnswerRe: Last call for help... HEEEELP!!!! Pin
_anil_5-Feb-06 15:58
_anil_5-Feb-06 15:58 
GeneralRe: Last call for help... HEEEELP!!!! Pin
Lord Kixdemp8-Feb-06 10:59
Lord Kixdemp8-Feb-06 10:59 
Question2872: 'IServiceProvider' : ambiguous symbol Pin
JerryMcguire5-Feb-06 8:46
JerryMcguire5-Feb-06 8:46 
AnswerRe: 2872: 'IServiceProvider' : ambiguous symbol Pin
ThatsAlok5-Feb-06 17:37
ThatsAlok5-Feb-06 17:37 
Questionmotherboard serial number in VC++ Pin
RomTibi5-Feb-06 7:07
RomTibi5-Feb-06 7:07 
AnswerRe: motherboard serial number in VC++ Pin
John M. Drescher5-Feb-06 8:12
John M. Drescher5-Feb-06 8:12 
GeneralRe: motherboard serial number in VC++ Pin
RomTibi5-Feb-06 9:52
RomTibi5-Feb-06 9:52 
GeneralRe: motherboard serial number in VC++ Pin
John M. Drescher5-Feb-06 10:37
John M. Drescher5-Feb-06 10:37 
GeneralRe: motherboard serial number in VC++ Pin
suchuhui5-Feb-06 19:40
suchuhui5-Feb-06 19:40 
GeneralRe: motherboard serial number in VC++ Pin
John M. Drescher6-Feb-06 4:39
John M. Drescher6-Feb-06 4:39 
GeneralRe: motherboard serial number in VC++ Pin
suchuhui8-Feb-06 14:41
suchuhui8-Feb-06 14:41 
GeneralRe: motherboard serial number in VC++ Pin
John M. Drescher6-Feb-06 4:42
John M. Drescher6-Feb-06 4:42 
GeneralRe: motherboard serial number in VC++ Pin
John M. Drescher6-Feb-06 4:47
John M. Drescher6-Feb-06 4:47 
GeneralRe: motherboard serial number in VC++ Pin
suchuhui5-Feb-06 19:26
suchuhui5-Feb-06 19:26 

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.