VC++6.0运行这段程序时编译和连接没有错误 执行时会出现xx.exe已停止工作,求大神指教
#include<iostream>#include<stdlib.h>#include<string>#include<fstream>#include<sys/typ...
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sys/types.h>
using namespace std;
int main(string sname)
{
sname="/abcd/ef";
string src = sname;
string src2;
char prova[40]="";
char app[40]="";
int ix = src.size() - 1;
//size()可以求得字符串的长度
while ((src[ix]!='/')&&(ix>=0)) ix--;
int ix2=0;
ix++;
while (ix<src.size()) {
prova[ix2]=src[ix];
ix2++;
ix++;
}
src2=prova;
printf("src2=%s\n",src2);
return 0;
} 展开
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sys/types.h>
using namespace std;
int main(string sname)
{
sname="/abcd/ef";
string src = sname;
string src2;
char prova[40]="";
char app[40]="";
int ix = src.size() - 1;
//size()可以求得字符串的长度
while ((src[ix]!='/')&&(ix>=0)) ix--;
int ix2=0;
ix++;
while (ix<src.size()) {
prova[ix2]=src[ix];
ix2++;
ix++;
}
src2=prova;
printf("src2=%s\n",src2);
return 0;
} 展开
1个回答
展开全部
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sys/types.h>
using namespace std;
int main(string sname)
{
sname="/abcd/ef";
string src = sname;
string src2;
char prova[40]="";
char app[40]="";
int ix = src.size() - 1; //size()可以求得字符串的长度
while ((src[ix]!='/')&&(ix>=0))
ix--;
int ix2=0;
ix++;
while (ix<src.size())
{
prova[ix2]=src[ix];
ix2++;
ix++;
}
src2=prova;
printf("src2=%s\n",prova); //这里!
return 0;
}
试试它,应该是字符串string和char数组之间的赋值有问题,自己找找!
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sys/types.h>
using namespace std;
int main(string sname)
{
sname="/abcd/ef";
string src = sname;
string src2;
char prova[40]="";
char app[40]="";
int ix = src.size() - 1; //size()可以求得字符串的长度
while ((src[ix]!='/')&&(ix>=0))
ix--;
int ix2=0;
ix++;
while (ix<src.size())
{
prova[ix2]=src[ix];
ix2++;
ix++;
}
src2=prova;
printf("src2=%s\n",prova); //这里!
return 0;
}
试试它,应该是字符串string和char数组之间的赋值有问题,自己找找!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询