num*_*l25 0 c++ visual-studio-2008
我正在尝试调试一些功课,但我遇到了这些代码行的问题
#include "stdafx.h"
#include<conio.h>
#include<iostream>
#include<string>
using namespace std;
int main()
{
char word;
cout << "Enter a word and I will tell you whether it is" << endl <<
"in the first or last half of the alphabet." << endl <<
"Please begin the word with a lowercase letter. --> ";
cin >> word;
if(word[0] >= 'm')
cout << word << " is in the first half of the alphabet" << endl;
else
cout << word << " is in the last half of the alphabet" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到以下错误,我不知道它的含义是什么
error C2109: subscript requires array or pointer type
Run Code Online (Sandbox Code Playgroud)
术语下标是指[]运算符的应用.在你word[0]的[0]部分是下标.
内置[]运算符只能与数组或指针一起使用.您正在尝试将它与类型的对象char(您word的声明为char)一起使用,它既不是数组也不是指针.这就是编译器告诉你的.