我从教程中编写了该代码以了解toupper
函数,但运行时,while语句的编译时错误cannot convert string type to bool
。有另一种方法来解决这个问题吗?无法将字符串类型转换为bool C++
#include <iostream>
#include <cctype>
#include <stdio.h>
using namespace std;
char toupper(char numb);
int main()
{
char c;
int w = 0;
string anArray[] = {"hello world"};
while (anArray[w])
{
c = anArray[w];
putchar (toupper(c));
w++;
}
}
实际上,anArray [w]是原始文章中的一个字符串。 anArray初始化为大小为1的字符串数组。因此,anArray [0]是字符串,并且anArray [1]超出数组末尾。 – Steger
所以在c中他们使用的数组主要是一系列数字或字符。现在在C++中,他们演变为字符串 – TheStache
@Adosi:你可以编辑你的答案纠正它有关anArray [w]?可能应该这样说:“anArray [0]是字符串...” – Steger