Question: Whenever I am trying to publish Azure Function for Python app on Azure Function then I got the below error:-

I want to publish azure function for python using the command line
command:- `func azure functionapp <Function Name> --Python`

[![enter image description here](https://i.stack.imgur.com/1sazP.png)](https://i.stack.imgur.com/1sazP.png)

But whenever I am trying it on local using `func host start` then it works.

Is there any way to resolve the above issue?

Answer: 
The output makes sense. Presumably you thought you were defining a string with 7 characters? Take a look at `str.size()`. You defined a string with 12 characters!

Even though you were able to type `"hello☺"` into your program, this string literal does not consist of just seven bytes. Each of the last two characters gets expanded into multiple bytes, as those characters fall outside the expanded ASCII range (0 to 255 or -128 to 127). The result is a 12-byte string literal, which initializes a 12-character `string`, which in turn initializes a 12-character `u32string`. You've mangled the characters you intended to represent.

***Example:*** The character `'☺'` is represented as the three bytes `\0xE2\0x98\0xBA`. If `char` is signed on your system (likely), these three bytes take on the values -30, -104, and -70. The conversion to `char32_t` promotes each of these values to 32 bits then converts signed to unsigned, resulting in the three values `4294967266`, `4294967192`, and `4294967226`. What you presumably wanted was to concatenate these bytes into the single `char32_t` value `\0x00E298BA`. However, your conversion does not provide a mechanism for (re-)combining bytes.

*Similarly, the character `''` is represented by the four bytes `\0xF0\0x9F\0x98\0x86`. These were converted into four 32-bit integers instead of the single value `\0xF09F9886`.*

To get the result you want, you need to tell the compiler to interpret your string literal as 7 characters. Try the following initialization of `s`:

```
std::u32string s = U"hello☺";

```

The `U` prefix on the string literal tells the compiler that each character represents a UTF-32 character. This results in the desired 7-character string (assuming your compiler and editor agree on character encodings, which I think is reasonably likely).

---

**Gratis debugging takeaway:** When your output is not what you expect, check the data at each stage to make sure your *input* is what you expect.
Thanks everybody for help!

Using these 2 links, I was able to found some relevant functions:

* <https://en.cppreference.com/w/cpp/string/multibyte/mbrtoc32>
* [How to convert a Unicode code point to characters in C++ using ICU?](https://stackoverflow.com/questions/23322438/how-to-convert-a-unicode-code-point-to-characters-in-c-using-icu)

I tried using `codecvt` functions, but I got the error:

```
fatal error: codecvt: No such file or directory
 #include <codecvt>
                   ^
compilation terminated.

```

So, I skipped that & on further searching, I found `mbrtoc32()` function which works:)

This is the working code:

```
#include <iostream>
#include <string>
#include <locale>
#include "unicode/unistr.h"
#include "unicode/ustream.h"
#include <cassert>
#include <cwchar>
#include <uchar.h>

int main()
{
    constexpr char locale_name[] = "";
    setlocale( LC_ALL, locale_name );
    std::locale::global(std::locale(locale_name));
    std::ios_base::sync_with_stdio(false);
    std::wcin.imbue(std::locale());
    std::wcout.imbue(std::locale());

    std::string str;
    std::cin >> str;
    //For example, the input string is "hello☺"

    std::mbstate_t state{}; // zero-initialized to initial state
    char32_t c32;
    const char *ptr = str.c_str(), *end = str.c_str() + str.size() + 1;

    icu::UnicodeString ustr;

    while(std::size_t rc = mbrtoc32(&c32, ptr, end - ptr, &state))
    {
      icu::UnicodeString temp((UChar32)c32);
      ustr+=temp;
      assert(rc != (std::size_t)-3); // no surrogates in UTF-32
      if(rc == (std::size_t)-1) break;
      if(rc == (std::size_t)-2) break;
      ptr+=rc;
    }

    std::cout << "Unicode string is: " << ustr << std::endl;
    std::cout << "Size of unicode string = " << ustr.countChar32() << std::endl;
    std::cout << "Individual characters of the string are:" << std::endl;
    for(int i=0; i < ustr.countChar32(); i++)
      std::cout << icu::UnicodeString(ustr.char32At(i)) << std::endl;

    return 0;
}

```

The output on entering input `hello☺` is as expected:

```
Unicode string is: hello☺
Size of unicode string = 7
Individual characters of the string are:
h
e
l
l
o
☺

```