首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

这个程序不懂`该如何处理

2012-02-10 
这个程序不懂``我刚开始学 书上用的编译器好象和我的不一样这个程序作用是处理无效的输入``有三个地方不懂

这个程序不懂``
我刚开始学 书上用的编译器好象和我的不一样
这个程序作用是处理无效的输入``有三个地方不懂
#include<exception>
#include<iostream>

  int main()
{
try
{
int i(0);
int biggest(0);
do
{
std::cout<<"type in a positive integer";
std::cout<<"(zero or a negative integer ends the program):";
std::cin>>i;
if(not std::sin)throw std::exception(); \\if里面的条件编译时通不过 该咋换?
if(i<1)break;
if(biggest<i)biggest=i;
}
while(true); \\true 我用1换 程序通过了 但是不知道对不对?
std::cout<<"the largest number input was"<<biggest<<'\n';
}
catch(...) \\这里的三点是什么意思 以前好象没有见过?
{
std::cerr<<"***an exception was throw.***\n";
}
} \\在线等``谢谢`````

[解决办法]
#include <exception> 
#include <iostream> 
using namespace std;

int main() 

try 

int i(0); 
int biggest(0); 
do 

std::cout <<"type in a positive integer" << endl; 
std::cout <<"(zero or a negative integer ends the program):"; 
std::cin>> i; 
//not不能直接写的,必须用:!
if( !std::cin)throw std::exception();
if(i <1)break; 
if(biggest <i)biggest=i; 
}
while(true); //true与1的意思一样的,true是非0的意思;
std::cout <<"the largest number input was" <<biggest <<'\n'; 

catch(...) //任何类型的异常处理; 

std::cerr <<"***an exception was throw.***\n"; 

}

热点排行