Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;与原始字符的比较失败?_C++_Comparison_Special Characters_Tolower - Fatal编程技术网

C++ C++;与原始字符的比较失败?

C++ C++;与原始字符的比较失败?,c++,comparison,special-characters,tolower,C++,Comparison,Special Characters,Tolower,我有以下C++代码: string StringTest = "Test"; bool OriginalWord = true; for (unsigned int i = 0; i < StringTest(); i++) { string Character = towlower(StringTest[i]); string CharacterOriginal = StringTest[i]; if (Character != CharacterOriginal

我有以下C++代码:

string StringTest = "Test";
bool OriginalWord = true;
for (unsigned int i = 0; i < StringTest(); i++) {
    string Character = towlower(StringTest[i]);
    string CharacterOriginal = StringTest[i];
    if (Character != CharacterOriginal) {
        //t vs. T should trigger false, but never happens?
        //e vs. e should trigger true
        //s vs. s should trigger true 
        //t vs. t should trigger true
        OriginalWord = false;
        }
    }
StringTest=“Test”;
bool OriginalWord=true;
for(无符号int i=0;i
请注意,我使用
towlow
而不是
tolower

这总是导致出现
OriginalWord=true
的情况。但是,例如,测试应该返回
OriginalWord=false
。因为
towlower(T)
将导致T和
CharacterOriginal=T
,这意味着它们不相同,因此
OriginalWord=false


我做错了什么?我猜它与
towlower
函数有关

字符串错误用法,它必须是字符,因为tolower返回int(char)而不是字符串。 还可以获取字符串长度->字符串测试。size()

编辑的代码在这里

string StringTest = "Test";
bool OriginalWord = true;
for (unsigned int i = 0; i < StringTest.size(); i++) {
    char Character = tolower(StringTest[i]);
    char CharacterOriginal = StringTest[i];
    if (Character != CharacterOriginal) {
        OriginalWord = false;
    }
}
StringTest=“Test”;
bool OriginalWord=true;
for(无符号int i=0;i
您在类型转换方面遇到了一些问题,因为类型转换不能使用更严格的编译器标志。请参见下面代码片段中的注释:

string StringTest = "Test";
bool OriginalWord = true;
for (unsigned int i = 0; i < StringTest.size(); i++) 
// do you mean StringTest.size() instead of StringTest()?
{
    wint_t Character = towlower(StringTest[i]);
    wint_t CharacterOriginal = StringTest[i];
// can't convert a char to a string (or const char *)
// did you meant to use wint_t instead of string?
    if (Character != CharacterOriginal) 
    {
        //t vs. T should trigger false, but never happens?
        //e vs. e should trigger true
        //s vs. s should trigger true 
        //t vs. t should trigger true
        OriginalWord = false;
    }
}
StringTest=“Test”;
bool OriginalWord=true;
for(无符号int i=0;i
好的, 您的代码中有一些问题, 第一:

StringTest=“Test”//您将StringTest创建为单个变量
//在接下来的步骤中,您将始终使用它作为数组,让我们更改它。
整数计数=10;
string StringTest[计数]={“测试”、“测试”、“测试”、“测试”、“测试”、“测试”、“测试”、“测试”、“测试”、“测试”、“测试”};
对于(unsigned int i=0;i
该代码甚至不应该编译,因为您试图从单个字符初始化
std::string
(从技术上讲是
std::wint\t
)(以及其他问题)。
i
?您将wstring(towlow)的方法与字符串方法(tolower)混为一谈。@Someprogrammerdude,它编译起来了:)@Martze,这听起来像是我的想法,但我不知道如何解决这个问题。我对C++非常陌生,这不是使用Towlow,而是tolower,不是一个选项
string StringTest = "Test"; // you created StringTest as a single variable
 //in the next steps you use it all the time as a array, lets change that.

int count = 10;
string StringTest[count] = { "Test", "test","Test", "test","Test", "test","Test", "test","Test", "test" };

for (unsigned int i = 0; i < StringTest(); i++) // you must use the size of string so:
for (unsigned int i = 0; i < count; i++)