Click here to Skip to main content
15,844,673 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SOLVED Re: error: member access into incomplete type Pin
Richard Andrew x6427-Nov-23 13:06
professionalRichard Andrew x6427-Nov-23 13:06 
AnswerRe: error: member access into incomplete type Pin
JudyL_MD27-Nov-23 11:21
JudyL_MD27-Nov-23 11:21 
QuestionApplication not Launching when converting from 32bit to 64bit in VS Pin
Member 1614225419-Nov-23 16:31
Member 1614225419-Nov-23 16:31 
AnswerRe: Application not Launching when converting from 32bit to 64bit in VS Pin
Richard MacCutchan19-Nov-23 22:41
mveRichard MacCutchan19-Nov-23 22:41 
AnswerRe: Application not Launching when converting from 32bit to 64bit in VS Pin
jschell20-Nov-23 8:23
jschell20-Nov-23 8:23 
QuestionC++ file handling Pin
Saboor Sarfraz18-Nov-23 8:11
Saboor Sarfraz18-Nov-23 8:11 
AnswerRe: C++ file handling Pin
Greg Utas18-Nov-23 9:42
professionalGreg Utas18-Nov-23 9:42 
AnswerRe: C++ file handling Pin
k505418-Nov-23 9:59
mvek505418-Nov-23 9:59 
It's just not that simple. A file is essentially an array of bytes on disc, which are written sequentially. There is no structure or other information, such as start of line, or record size or anything like that associated with a file(1). When you write a Carriage Return ('\r' hex 0D) to the file, it just appends a CR character at the current location in the file.

Exactly what you need to do, depends on what your exercise is.

If you've got a single string of text as shown above, you'll need to examine each character and decide what to do when you find either a '\n' (start a new line) or a '\r' (move to the beginning of the current line). When you find a newline character, you'll need to write that to the file, and use tellp() to record the current location. When you find a CR ('\r') you'll want to then use seekp() to move to the location returned by the previous tellp(). Don't forget to initialize the variable you use for the result of tellp() when you open the file.

If, on the other hand, you have pairs of input, e.g an initial string ("This is some text") and then the text to overwrite ("Overwrite") then its a bit simpler. You still need to record your current location in the file, but you won't need to examine each character for a CR or NL. You just need to record where you are in the file before you write the line, then use seekp() to move back there when you get the next line of input.

In both cases, you may need to think about what happens when you have multiple lines of input. Are you expected to then move to then end of the current line and continue on, or continue writing at the current file cursor location.

If you know you will only have a single line of text, followed by a single line to overwrite with, things are simpler still. In this case, you just need to write the first line of text, then seekp(0) to the beginning of the file, and write the second line of text.

Note:
(1) This might not be true for all OS's out there. But if you're using Windows, Linux or OS-X, then that is the case.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown

AnswerRe: C++ file handling Pin
jschell20-Nov-23 8:30
jschell20-Nov-23 8:30 
Question&foo[bar] or (foo + bar) ? Pin
honey the codewitch16-Nov-23 12:48
mvahoney the codewitch16-Nov-23 12:48 
AnswerRe: &foo[bar] or (foo + bar) ? Pin
k505416-Nov-23 17:14
mvek505416-Nov-23 17:14 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
JudyL_MD17-Nov-23 4:15
JudyL_MD17-Nov-23 4:15 
AnswerRe: &foo[bar] or (foo + bar) ? Pin
CPallini16-Nov-23 21:08
mveCPallini16-Nov-23 21:08 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
Peter_in_278017-Nov-23 19:28
professionalPeter_in_278017-Nov-23 19:28 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
Richard MacCutchan17-Nov-23 23:11
mveRichard MacCutchan17-Nov-23 23:11 
AnswerRe: &foo[bar] or (foo + bar) ? Pin
Richard MacCutchan16-Nov-23 22:29
mveRichard MacCutchan16-Nov-23 22:29 
AnswerRe: &foo[bar] or (foo + bar) ? Pin
jschell17-Nov-23 6:36
jschell17-Nov-23 6:36 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
honey the codewitch17-Nov-23 6:38
mvahoney the codewitch17-Nov-23 6:38 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
trønderen17-Nov-23 9:35
trønderen17-Nov-23 9:35 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
honey the codewitch17-Nov-23 9:37
mvahoney the codewitch17-Nov-23 9:37 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
trønderen17-Nov-23 12:07
trønderen17-Nov-23 12:07 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
jschell20-Nov-23 8:11
jschell20-Nov-23 8:11 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
honey the codewitch20-Nov-23 8:20
mvahoney the codewitch20-Nov-23 8:20 
AnswerRe: &foo[bar] or (foo + bar) ? Pin
JudyL_MD17-Nov-23 8:53
JudyL_MD17-Nov-23 8:53 
GeneralRe: &foo[bar] or (foo + bar) ? Pin
honey the codewitch17-Nov-23 8:53
mvahoney the codewitch17-Nov-23 8:53 

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.