返回列表 发帖

c++入门到实践上机实践问题

我在做2.6章节上机时践时出现以下问题,求解答,感谢!
2.6.2运行光盘源代码问题
#include<iostream.h>
int main(void)
{
        bool b;
        bool a;
        cin>>a;
        cin>>b;
        cout<<"!a="<<!a<<endl;
        cout<<"a&&b : "<<(a&&b)<<endl;
        cout<<"a||b :"<<(a||b)<<endl;
        return 0;
}
提示如下:
--------------------Configuration: ch2_8 - Win32 Debug--------------------
Compiling...
ch2_8.cpp
e:\c++\c++光盘文件\源文件\第02章\ch2_8\ch2_8.cpp(6) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'bool' (or there is no acceptable conversion)
e:\c++\c++光盘文件\源文件\第02章\ch2_8\ch2_8.cpp(7) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'bool' (or there is no acceptable conversion)
Error executing cl.exe.

ch2_8.obj - 2 error(s), 0 warning(s)
求解.

2.6.3光盘源代码可运行,我自己输入不可运行
具体步骤:
1.Microsoft Visual C++ 6.0->file->new->win32 console application->a simple application->在文件名.cpp里面输入代码:
#include "stdafx.h"

int main(void)
{
        char ch1='a';
        char ch2;
        int ascii;
        ascii=(int)ch1;
        cout<<ascii<<endl;
        ch2=(char)(ascii+1);
        cout<<ch2<<endl;
        return 0;
}
出现以下问题,求解:
Compiling...
二点六三.cpp
e:\c++\工程代码存放\二点六三\二点六三.cpp(1) : fatal error C1083: Cannot open precompiled header file: 'Debug/二点六三.pch': No such file or directory
Error executing cl.exe.

二点六三.obj - 1 error(s), 0 warning(s)
分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友

1# xiaozetian


按照错题,你的代码没有问题。只是环境配置问题。从现在来判断,有可能是你的目录有问题。建议把目录修改一下,尽量不要使用+号。

TOP

2.6.2运行光盘源代码问题
a、b的类型不对,不应该为bool型,改为int或者其他就可以了。
#include<iostream.h>
int main(void)
{
        int b;
        int a;
        cin>>a;
        cin>>b;
        cout<<"!a="<<!a<<endl;
        cout<<"a&&b : "<<(a&&b)<<endl;
        cout<<"a||b :"<<(a||b)<<endl;
        return 0;
}
2.6.3光盘源代码可运行问题:
帮"stdafx.h"改为<iostream.h>
去掉main后面的void,更改以后的代码如下:
#include <iostream.h>
int main()
{
        char ch1='a';
        char ch2;
        int ascii;
        ascii=(int)ch1;
        cout<<ascii<<endl;
        ch2=(char)(ascii+1);
        cout<<ch2<<endl;
        return 0;
}

TOP

返回列表