Click here to Skip to main content
15,906,208 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to use MFC to design an app that can connect 2 types of database Pin
Jochen Arndt19-Mar-15 23:29
professionalJochen Arndt19-Mar-15 23:29 
AnswerRe: How to use MFC to design an app that can connect 2 types of database Pin
jschell20-Mar-15 13:06
jschell20-Mar-15 13:06 
QuestionTo copy path of selected file or folder Pin
Member 1147315918-Mar-15 7:33
Member 1147315918-Mar-15 7:33 
QuestionRe: To copy path of selected file or folder Pin
jeron118-Mar-15 8:11
jeron118-Mar-15 8:11 
AnswerREPOST Pin
Richard Deeming18-Mar-15 8:37
mveRichard Deeming18-Mar-15 8:37 
QuestionHow to fast read excel file, with VC2005 Pin
lichengbyd18-Mar-15 2:46
lichengbyd18-Mar-15 2:46 
AnswerRe: How to fast read excel file, with VC2005 Pin
Jochen Arndt18-Mar-15 3:09
professionalJochen Arndt18-Mar-15 3:09 
GeneralRe: How to fast read excel file, with VC2005 Pin
lichengbyd18-Mar-15 3:50
lichengbyd18-Mar-15 3:50 
GeneralRe: How to fast read excel file, with VC2005 Pin
Jochen Arndt18-Mar-15 4:02
professionalJochen Arndt18-Mar-15 4:02 
GeneralRe: How to fast read excel file, with VC2005 Pin
lichengbyd18-Mar-15 4:30
lichengbyd18-Mar-15 4:30 
QuestionWriting Vector object into a .txt file Pin
Member 935023718-Mar-15 0:16
Member 935023718-Mar-15 0:16 
AnswerRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 0:46
professionalJochen Arndt18-Mar-15 0:46 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023718-Mar-15 1:38
Member 935023718-Mar-15 1:38 
AnswerRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 1:59
professionalJochen Arndt18-Mar-15 1:59 
You can do it similar using sprintf() to print to a buffer and then write the buffer to file:
C++
char buffer[128];
char *p = buffer;
int n = sprintf(p, "%lf %lf %lf\r\n", newForce.x, newForce.y, newForce.z);
s += n;
sprintf(p, "%lf %lf %lf\r\n", newForce1.x, newForce1.y, newForce1.z);
FILE *f = fopen(fileName, "wb");
fwrite(buffer, 1, strlen(buffer), f);
fclose(f);

But as you can see this is much more code and it is insecure without checking for buffer overflows (which adds more code).

If you don't need the data to be in text format (e.g. only loaded by your application), it might be better to write the data to a binary file. That solves also the problem of inaccuracies when converting floating point values to text and back again later.
Example:
C++
FILE *f = fopen(fileName, "wb");
fwrite(&newForce.x, sizeof(newForce.x), 1, f);
// Write other items here
fclose(f);

Reading is then done in a similar way:
C++
FILE *f = fopen(fileName, "rb");
fread(&newForce.x, sizeof(newForce.x), 1, f);
// Read other items here
fclose(f);

GeneralRe: Writing Vector object into a .txt file Pin
Member 935023718-Mar-15 5:03
Member 935023718-Mar-15 5:03 
AnswerRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 5:19
professionalJochen Arndt18-Mar-15 5:19 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023718-Mar-15 6:33
Member 935023718-Mar-15 6:33 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 6:59
professionalJochen Arndt18-Mar-15 6:59 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023718-Mar-15 22:32
Member 935023718-Mar-15 22:32 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 22:44
professionalJochen Arndt18-Mar-15 22:44 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023719-Mar-15 22:27
Member 935023719-Mar-15 22:27 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt19-Mar-15 22:29
professionalJochen Arndt19-Mar-15 22:29 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023723-Mar-15 5:12
Member 935023723-Mar-15 5:12 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt23-Mar-15 5:57
professionalJochen Arndt23-Mar-15 5:57 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023723-Mar-15 6:20
Member 935023723-Mar-15 6:20 

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.