UTF-8输入有问题

问题描述

我的简单代码在输出时日语字符没有问题,但是由于某种原因,它不能正确输入,是否缺少某些东西?

btnShow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchID = txtid.getText().toString().trim();
            DatabaseReference readRef = FirebaseDatabase.getInstance().getReference();
            DatabaseReference dref = readRef.child("Student");
            Query query = dref.orderByChild("id").equalTo(searchID);
            query.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    if(dataSnapshot.hasChildren()){
                        txtID.setText((dataSnapshot.child("id").getValue().toString()));
                        txtName.setText((dataSnapshot.child("name").getValue().toString()));
                        txtAdd.setText((dataSnapshot.child("address").getValue().toString()));
                        txtConNo.setText((dataSnapshot.child("conNo").getValue().toString()));
                    }
                    else
                        Toast.makeText(getApplicationContext(),"No Source to Display",Toast.LENGTH_SHORT).show();

                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {

                }
            });
        }
    });

解决方法

此代码在Windows 10命令提示符下对我有用。关于_O_标志的解释不多...

#include <fcntl.h>
#include <io.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    _setmode(_fileno(stdout),_O_U16TEXT); // _O_WTEXT also worked
    _setmode(_fileno(stdin),_O_WTEXT);   // only _O_WTEXT worked

    wstring s = L"こんにちは,世界!\nHello,World!";
    wcout << s << endl;

    wstring test;
    getline(wcin,test);
    wcout << test << endl;
    return 0;
}

输出:

C:\>test
こんにちは,世界!
Hello,World!
你好马克!                << input line
你好马克!

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...