简体   繁体   English

无法让法语字符在 C++ 中工作

[英]Can't get french characters to work in C++

// francais projecct test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
    char  userAnswer[10];
    char answer[] = { "Vous êtes" };

    wcout << "s'il vous plaat ecrire conjugation pour Vous etre: ";

    cin>>userAnswer;

    if (strcmp(userAnswer, answer) == 0)

        cout << endl << "correct"<<endl<<endl;
    else
        cout << endl << "wrong answer"<<endl<<endl;

    system("pause");
    return 0;
}

The accented characters aren't recognized by the compiler and I don't know how to get input of unicode characters if unicode is required.编译器无法识别重音字符,如果需要 unicode,我不知道如何输入 unicode 字符。

std::getline is defined for std::basic_string (specialized cases include std::string , std::wstring ). std::getline是为std::basic_string定义的(特殊情况包括std::stringstd::wstring )。 Normal character arrays don't fall in that category.普通字符数组不属于该类别。

Reference: http://www.cplusplus.com/reference/string/string/getline/参考: http : //www.cplusplus.com/reference/string/string/getline/

Though I would highly recommend you to use std::string / std::wstring , If you want to make your code work, you must use cin.getline in your case.虽然我强烈建议您使用std::string / std::wstring ,但如果您想让代码正常工作,则必须在您的情况下使用cin.getline

You may refer to Example 2 in this: https://www.programiz.com/cpp-programming/library-function/iostream/wcin您可以参考示例 2: https : //www.programiz.com/cpp-programming/library-function/iostream/wcin

Secondly, userAnswer == answer is wrong as it will compare two pointers, not their actual content.其次, userAnswer == answer是错误的,因为它会比较两个指针,而不是它们的实际内容。

For doing so, you should use strcmp() .为此,您应该使用strcmp()

Reference: http://www.cplusplus.com/reference/cstring/strcmp/参考: http : //www.cplusplus.com/reference/cstring/strcmp/

Something like this:像这样的东西:

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
    char userAnswer[10];
    char answer[] = "Vous etes";

    wcout <<"s'il vous plait ecrire conjugation pour Vous etre: ";
    cin.getline(userAnswer, 10);

    if (!strcmp(userAnswer, answer))
    {
        wcout <<endl<< "correct";
    }
    else
    {
        wcout <<endl<< "wrong answer";
    }

    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM