warning C4244 : VS 2019

Anonymous
2020-12-11T05:11:57.297+00:00

While building a VC++ solution in VS 2019 I am getting the below error. I did some googling and couldn't find a solution.

" warning C4244: 'argument': conversion from 'wchar_t' to 'const _Elem', possible loss of data"

It arises from a file called xtring:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\include\xstring(2390,23):

What could be the reason. Could someone please help?

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
1,040 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2020-12-26T12:27:16.233+00:00

    Just write any code, that includes <xstring>. Warning is here:

    template <class _Iter>
        void _Construct(_Iter _First, const _Iter _Last, input_iterator_tag) {
            // initialize from [_First, _Last), input iterators
            _Tidy_deallocate_guard<basic_string> _Guard{this};
            for (; _First != _Last; ++_First) {
                push_back(*_First); // <==== Here we have this warning
            }
    
            _Guard._Target = nullptr;
        }
    

    C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.27.29110\include\xstring(2390,23): warning C4244: 'argument': conversion from 'wchar_t' to 'const _Elem', possible loss of data
    with
    [
    _Elem=char
    ]

    0 comments No comments

  2. Anonymous
    2020-12-26T14:11:16.603+00:00

    More details: it happens in code like this:

    std::string foo("123");
    std::wstring bar(foo.begin(), foo.end());


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.