Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Writing a char* to a text file?

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
chinese_bunny
Asked:
chinese_bunny
  • 4
  • 3
1 Solution
 
AxterCommented:
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
 
chinese_bunnyAuthor Commented:
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
 
chinese_bunnyAuthor Commented:
Could a mod/admin remove my question please? Thank you!!

<333
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
AxterCommented:
>>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
 
AxterCommented:
>> did some other things and was able to get it to work.

What did you do to get it to work?
0
 
Jaime OlivaresSoftware ArchitectCommented:
outdata << std::string(L_username) << "\n";
0
 
AxterCommented:
The more efficient method, would just be to send it direct via the (LPCTSTR) CString operator.
Example:
outdata <<  (LPCTSTR) L_username << "\n";
0
 
chinese_bunnyAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now