注册 登录
编程论坛 C++教室

C++课本上的题目

yi19860699 发布于 2010-05-18 21:30, 517 次点击
// jump.cpp -- using continue and break
#include <iostream>
const int ArSize = 80;
int main()
{
    using namespace std;
    char line[ArSize];
    int space = 0;
    cout << "Enter a line of text: \n";
    cin.get (line,ArSize);
    cout << "Complete line:\n" << line << endl;
    cout << "Line through first period:\n";
    for (int i = 0; line[i] !='\0'; i++)
    {
        cout << line[i];
        if(line[i] == ".")
            break;
        if(line[i] !=' ')
             space++;

    }
    cout << "\n" << space << " spaces\n";
    cout << "Done.\n";
    return 0;
}
error C2446: '==' : no conversion from 'char *' to 'int'
error C2040: '==' : 'int' differs in levels of indirection from 'char [2]'
Error executing cl.exe.
报错,麻烦大侠帮已修正
4 回复
#2
lpf120342010-05-18 21:49
"."改成单引号
#3
最近不在2010-05-18 23:52
"." //""是用来指示字符串的,里面隐含/0,修饰单个字符应用''.在cout时这2种输出单个字符区别不大
#4
aiyinsitan2010-05-19 06:28
顶楼上两位
#5
apull2010-05-19 10:32
if(line[i] == ".")有问题。。
line[i]是char类型
"."是char*类型,不能比较。
字符要用单引号'.'。。或者直接比较ascii码。

改成
if(line[i] == '.')

下面一样。

1