?
Solved

Writing a char* to a text file?

Posted on 2005-03-06
8
Medium Priority
?
277 Views
Last Modified: 2013-11-20
I converted a CString to a char* and i was wondering how I could write that to a text file?
The size of how long the Cstring (L_username) is variable every time:

      char* temp = (LPTSTR)(LPCTSTR) L_username;
      outdata << *temp << "\n";

right now it will only print out the first character of the char array...how do i print it out character by character until I reach the null at the end without the physical char array to go through?

Thank you! <333
0
Comment
Question by:chinese_bunny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 13473000
Hi chinese_bunny,
>> outdata << *temp << "\n";

The above line of code is dereferencing the pointer because of the asterik.
Try the following instead:
outdata << temp << "\n";
0
 

Author Comment

by:chinese_bunny
ID: 13473048
I do want to de-reference the pointer since i want to print out the value its pointing to, and not the memory location.
i did some other things and was able to get it to work.

Thank you anyways.
=)
0
 

Author Comment

by:chinese_bunny
ID: 13473060
Could a mod/admin remove my question please? Thank you!!

<333
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 30

Expert Comment

by:Axter
ID: 13473193
>>I do want to de-reference the pointer since i want to print out the value its pointing to, and not the memory location.

The solution I posted does not print out the memory location, and instead will print out the entire string.

>>Could a mod/admin remove my question please? Thank you!!
I have answered your question, so IMHO, this question should not be deleted.
0
 
LVL 30

Expert Comment

by:Axter
ID: 13473206
>> did some other things and was able to get it to work.

What did you do to get it to work?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13473275
outdata << std::string(L_username) << "\n";
0
 
LVL 30

Accepted Solution

by:
Axter earned 375 total points
ID: 13473296
The more efficient method, would just be to send it direct via the (LPCTSTR) CString operator.
Example:
outdata <<  (LPCTSTR) L_username << "\n";
0
 

Author Comment

by:chinese_bunny
ID: 13478440
i had just cast it to a char* and then printed it out one character at a time to the file by incrementing the pointer.

when i just do outdata<<temp, i do get the actuall memory address instead of the value.  That was the first thing i had tried -=P

but i will accept outdata <<  (LPCTSTR) L_username << "\n";
as the answer.

thank you. =)
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question