异常处理的问题
// ssh.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
void main(int argc, char * * argv)
{
ifstream source("argv");
char line[128];
try
{
if(source.fail())
{
cout<<"in try"<<endl;
throw argv[1];
}
}
catch (char *s)
{
cout<<"error opening the file"<<endl;
cout<<s<<endl;
cout<<"in catch"<<endl;
exit(1);
}
while(!source.eof())
{
source.getline(line,sizeof(line));
cout<<line<<endl;
}
source.close ();
}
程序在执行到catch的地方出了问题????
问题点数:20、回复次数:7Top
1 楼xiaocai0001(高楼目尽欲黄昏/梧桐叶上萧萧雨)回复于 2005-12-02 18:35:10 得分 0
ifstream source("argv");
这个是什么意思?Top
2 楼ssh000(如风似水)回复于 2005-12-02 18:35:41 得分 0
不好意思,呢个ifstream source(argv[1]);Top
3 楼xiaocai0001(高楼目尽欲黄昏/梧桐叶上萧萧雨)回复于 2005-12-02 18:36:27 得分 0
其他的没什么问题Top
4 楼xiaocai0001(高楼目尽欲黄昏/梧桐叶上萧萧雨)回复于 2005-12-02 18:38:04 得分 0
在执行程序的时候, 一定要给一个参数, 否则argv[1]的内容将是无定义的. 在输出的时候就有可能出错.Top
5 楼ssh000(如风似水)回复于 2005-12-02 18:39:54 得分 0
现在可以了吧??
Top
6 楼ssh000(如风似水)回复于 2005-12-02 18:40:47 得分 0
怎么给参数啊
xiaocai0001(萧筱雨)Top
7 楼xiaocai0001(高楼目尽欲黄昏/梧桐叶上萧萧雨)回复于 2005-12-02 18:42:40 得分 0
在
Project -> Settings -> Debug -> Program arguments
下面填入你所需要打开的文件名.Top




