我在使用这个程序时遇到了问题。编译器在成功编译程序后给我这个:“0x0f6bd540(msvcr100d.dll)”中的未处理异常“progBUS.exe”
程序有什么问题,因为一切似乎都运行良好,但最后,在按下“ Enter" 退出控制台,错误 - 给出未处理的异常。如何解决?非常感谢!
# include <iostream>
# include <cstring>
using namespace std;
template < class T>
void switcher(T &a, T &b){
T c=a;
a=b;
b=c;
}
char* f(char* word){
static char* ss("u");
static int iter(0);
cout<<"word \""<<word<<"\" has been thrown\n";
if ( strcmp(word,ss)!=0 && strcmp(word,"")!=0) {ss=word; iter=0;} //if another word has been thrown
cout<<"ss="<<ss<<" iter="<<iter<<endl;
static char ret[15];//return word value
memset(ret, '\0', 14);//clean up ret value
int len = strlen(ss);
int j=0;
if (iter == len-1) return nullptr;//we have reached the end of word
for (int i=iter;i<len;i++){
//cout<<"*(ss+i)="<<*(ss+i)<<endl;
if (*(ss+i)!=' ') ret[j]=*(ss+i);
else { iter=i+1; return ret;}
//cout<<*(ss+i);
j++;
if(i==len-1) {iter=i+1; return ret;}
}
return nullptr;
}
int main(){
int a=1,b=2;
cout<<f("fr rewfer ewr")<<endl;
cout<<f("fr rewfer ewr")<<endl;
cout<<f("43 34")<<endl;
cout<<f("")<<endl;
cout<<f("")<<endl;
cout<<f("fr rewfer ewr")<<endl;
//char ss[]("fr rewfer ewr");
//size_t len = (sizeof ss)/(sizeof ss[0]);
// cout<<"len="<<len<<endl;
system("PAUSE");
return 0;
}