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 8002065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:27+00:00 2026-06-04T16:15:27+00:00

#ifndef UNICODE #define UNICODE #endif #include <Windows.h> #include <cstdio> #include <fstream> using namespace std;

  • 0
#ifndef UNICODE
#define UNICODE
#endif

#include <Windows.h>
#include <cstdio>
#include <fstream>

using namespace std;

int main()
{
    FILE* resFile;
    char multiByteStr[256];
    ifstream oFile;
    FILE* exampleFile;
    TCHAR buffer[256];      
    system("chcp 65001");

    resFile = _wfopen(L"foo",L"w, ccs=UTF-8");             
    fwprintf(resFile,L"%s",L"C:\\exsistingFolder\\zażółć gęśłą jaźń ☺☻♥♦• ć.txt");    
    fclose(resFile);   

    oFile.open(L"foo");    
    oFile.getline(multiByteStr,256,'\n');       
    oFile.close();    

    MultiByteToWideChar(CP_UTF8,0,multiByteStr,256,buffer,256);    
    wprintf(L"%s",buffer);

    exampleFile = _wfopen(buffer,L"w, ccs=UTF-16LE");       
    fwprintf(exampleFile,L"%s",buffer);     
    fclose(exampleFile);

    system("pause");
    return 0;
}

As you can see, program should create file “foo” resFile that contains a full path of the file to be created, and this new file exampleFile should contain a path to itself. Although during debugging in Visual studio 2010 autos yields that buffer has the correct string, exampleFile isn’t created. Why?
And another thing: why wprintf doesn’t output extended characters, though I’ve switched console’s font to Lucida Console – that one which can deal with uncode characters.

Ps. exampleFile points to NULL, even after _wfopen, and the last character of buffer is '/0'.

  • 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-06-04T16:15:28+00:00Added an answer on June 4, 2026 at 4:15 pm

    The solution is very trivial- _wfopen creates a file encoded in UTF-8 with BOM, and MultiByteToWideChar function doesn’t remove the BOM, so we need to manually get rid of this.

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

Sidebar

Related Questions

#ifndef UNICODE #define UNICODE #endif #include <stdio.h> #include <Windows.h> int main(void) { TCHAR greeting[50]
//// header file #ifndef _SECTION_ #define _SECTION_ #include <map> #include Employee.h using namespace std;
#ifndef UNICODE #define UNICODE #endif #include <Windows.h> #include <cstdio> TCHAR* getSystemVolumine() { TCHAR volumine[2];
I have the following class #ifndef Container_H #define Container_H #include <iostream> using namespace std;
#ifndef DELETE #define DELETE(var) delete var, var = NULL #endif using namespace std; class
#ifndef SLIST_H #define SLIST_H #include llist.h using namespace std; class slist:public llist{ public: slist();
#ifndef MIGRATINGUSER_H #define MIGRATINGUSER_H #include <iostream> using namespace std; class MigratingUser { public: void
#ifndef __DynTex_H__ #define __DynTex_H__ #include SdkSample.h using namespace Ogre; using namespace OgreBites; class _OgreSampleClassExport
#ifndef MACROS_NULLCHECK_H_ #define MACROS_NULLCHECK_H_ #include <assert.h> #define NULLCHECK(x) assert(x != (void *) 0); #endif
FILE #1 (foo.h): #ifndef FOO_H_ #define FOO_H_ #include baseclass.h #include bar.h class Bar; class

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.