Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:12:26+00:00 2026-05-28T20:12:26+00:00

Im wriitng some data in File.But it doesnot write this properly. Code: CString sFileName

  • 0

Im wriitng some data in File.But it doesnot write this properly.
Code:

CString sFileName = "C:\\Test.txt";
CFile gpFile;

    CString testarr[10] = {"Tom","Ger","FER","DER","SIL","REM","FWE","DWR","SFE","RPOP"};

    if (!gpFile.Open( sFileName,CFile::modeCreate|CFile::modeWrite))
    {
        AfxMessageBox( sFileName + (CString)" - File Write Error");      
        return;
    }
   else
   {
      gpFile.Write(testarr,10);
   }

    AfxMessageBox("Completed");
    gpFile.Close(); 

It shows the file as
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:12:27+00:00Added an answer on May 28, 2026 at 8:12 pm

    That’s probably because you’re using CFile incorrectly. The first parameter to CFile::Write should be a buffer whose bytes you’d like to write to the file. However, testarr is more like a “buffer of buffers”, since each element of testarr is a string, and a string is itself a sequence of bytes.

    What you would need to do instead is either concatenate the elements of testarr, and then call CFile::Write. Or (probably more practical), iterate over testarr printing each string one at a time, e.g. for your particular example, the following should do what you’re looking for:

    for(int i = 0; i < 10; ++i)
    {
        gpFile.Write(testarr[i], strlen(testarr[i]));
    }
    

    There may be some built-in way to accomplish this, but I’m not really familiar with MFC, so I won’t be much help there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a test program to copy some file in Application data folder
I'm writing some data to a plist file but it fails on the device
I am writing some data to XML file...but when I open it all the
I am writing some Java code to read each line of a data file
I am writing some data access code and I want to check for potentially
I'm writing some code that handles logging xml data and I would like to
I thought I would write some quick code to download the number of fans
I have a file which is an XML representation of some data that is
I am writing some data(string) to a plist like this: NSError *error = nil;
I have a class that represents some file data. The file contains some headers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.