【问题标题】:C++ gives an errorC++ 给出一个错误
【发布时间】:2013-03-22 23:42:53
【问题描述】:

您好,我在这个程序中有一个错误,即 wcout 不是 `std' 的成员。如您所见,我也使用了iostream,但没有用。我有Dev-C++ 4.9.9.2,我的操作系统是XP SP3 我需要你的帮助。 感谢您的空闲时间。

#include <iostream>
#include <cstring>
#include <cwchar>
using namespace std;
const wchar_t alphabet[] ={'A', 'B', 'C', 'Ç', 'D', 'E', 'F', 'G', 'Ğ', 'H', 'I',
                        'İ', 'J', 'K', 'L', 'M', 'N', 'O', 'Ö', 'P', 'R', 'S',
                        'Ş', 'T', 'U', 'Ü', 'V', 'Y', 'Z', '0', '1', '2', '3',
                        '4', '5', '6', '7', '8', '9', '.', ',', ':', ';', ' '};
const int char_num =44;

void cipher(wchar_t word[], int count, int key)
{
    int i = 0;
    while(i < count) {
        int ind = -1;
        while(alphabet[++ind] != word[i]) ;
        ind += key;
        if(ind >= char_num)
            ind -= char_num;
        word[i] = alphabet[ind];
        ++i;
    }
}

void decipher(wchar_t word[], int count, int key)
{
    int i = 0;
        while(i < count) {
        int ind = -1;
        while(alphabet[++ind] != word[i]) ;
        ind -= key;
        if(ind < 0)
            ind += char_num;
        word[i] = alphabet[ind];
        ++i;
    }
}

int main()
{
    wchar_t text[] = L"ABJT;";
    int len = wcslen(text);
    std::wcout << text << std::endl;
    cipher(text, len, 2);
    std::wcout << text << std::endl;
    decipher(text, len, 2);
    std::wcout << text << std::endl;
    return 0;
}

【问题讨论】:

  • 您是否尝试过更新版本的dev-c++ with mingw
  • 我现在试过了,同样的问题:(
  • 您在尝试新版本之前是否先卸载了旧版本?我刚刚对其进行了测试,它对我来说编译得很好。

标签: c++


【解决方案1】:

如果您使用 MinGW 进行编译,wide characters are not yet supported。如果您确实需要它,另一种方法是使用 STLPort 库作为 libstdc++ 的替代方案。

【讨论】:

  • 有趣的是,wcoutwstring 在我记忆中使用我的 MinGW 已经工作了很长时间。
  • @chris 也许它最近被移植并且提问者使用的是旧版本?但该页面尚未更新。
  • 可能。我注意到 MinGW 网站的某些部分过去没有得到维护。
【解决方案2】:

您正在使用的 Dev-C++ 4.9.9.2 附带 7+ years old 的 MinGW-gcc 3.4.2,可能没有 sftrabbit 建议的正确支持宽字符。

如果您在 sourceforge 查看原始 Dev-C++ 的顶部,您会发现它已被 Orwell Dev-C++ 取代。如果您需要宽字符支持,我建议您使用它,因为它包含更新版本的 MinGW-gcc。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-22
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 2011-11-21
    • 1970-01-01
    相关资源
    最近更新 更多