Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


writing to a file

writing to a file

writing to a file

I am working a project in Visual Studio 2008, using C++ that is started using a custom wizard.  The wizard was provided by the vender and their starter code works fine.  It appears to be in .NET but I do not have sufficient knowledge to determine the exact style in terms of MFC, CLR, etc.  I need to grab some data and write it to a file.  I'll start with a text file, then add a binary file.  Here are the relevant lines of the nonsense I have so far.

int number1 = 11;
int number2 = 22;

CString tempBuffer;
TCHAR pfileName = _T("C:\temp.txt");
CStiolFile f1;
f1.Open( pFileName, Cfile::modeCreate | <and someother options>);

tembBuffer = "\nnumber1:" + number1 + " number2" + number2;
f1.WriteWtring( tempBuffer );

This code writes "number is" but does not get the value.

I tried:

tempBuffer.Format(" number1 is %d", number1 );

But then the compiler complained about the line several lines up:
TCHAR pfileName = _T("C:\temp.txt");
saying T is an unrecognized character escape sequence.

In summary, I just need to open a file and write a bunch of values to it.
It always seems that the easy and simple stuff is so hard to find. But maybe I'm barking up the wrong tree.  Give me some direction and I will be glad to use a different concept that is more appropriate.

Thank you

RE: writing to a file


That's all. Remember string literal syntax...

RE: writing to a file

Thanks for taking the time to respond, but that's not my problem.  Obviously I left out the \\ when writing the post.
The problem is this:
tembBuffer = "\nnumber1:" + number1 + " number2" + number2;
How do I get the values of the numbers into the string so they can be written to the file?


RE: writing to a file

After more searches I finally found I can do this:
int temp_data = 13;
CString temp_string;
temp_string.Format( _T("\ntemp_data is: %d", temp_data ));
f1.WriteString( temp_string );

But when I look in the file, it contains:

temp_data is 899889814

I don't know how 13 translates to that, but it appears there is something I have omitted.

Second question:  Is this the best basic technique to use for going forward within MFC when using Visual Studio C++, or maybe C#?


RE: writing to a file



temp_string.Format( _T("\ntemp_data is: %d"), temp_data );

RE: writing to a file

Thank you, I have it working now.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close