关于C++中使用string进行异或运算?

weixin_38074560 2016-03-03 06:43:30
#include <iostream> #include <string> #include <ctime> using namespace std; string Key=" "; string *p_Key=&Key; void bitcode(string *p_src,string *p_obj) { for(int i=0;i<(*p_src).length();i++) { char c=(*p_src)[i]^Key[i]; (*p_obj)[i]=c; } } void makeKey(string *p_src) { for(int i=0;i<(*p_src).length();i++) (*p_Key)[i]=rand()%10+'0'; } void main(void) { string srcstr="How are you?"; string *p_srcstr=&srcstr; string objstr=" "; string *p_objstr=&objstr; srand(time(NULL)); makeKey(p_srcstr); bitcode(p_srcstr,p_objstr); cout<<"密文:"<<*p_objstr<<endl; cout<<*p_Key<<endl; //bitcode(p_objstr,p_srcstr); //前面运行没问题 此处运行提示内存溢出 cout<<"明文:"<<*p_srcstr<<endl; system("pause"); } 运行后程序后部分提示string内存溢出,请问为什么呢?谢谢!
...全文
204 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复

474

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧