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

为什么小弟我的程序会出错,各位大大帮忙,多谢

2012-02-22 
为什么我的程序会出错,各位大大帮忙,谢谢程序目的:将10个字符串排序#includeiostream#includestring#i

为什么我的程序会出错,各位大大帮忙,谢谢
程序目的:将10个字符串排序

#include   <iostream>
#include   <string>
#include   <iomanip>
using   namespace   std;
int   main()
{
string   str[10];
string   *p   =   NULL;
int   i,   j;

for   (   i   =   0;   i   <   10;   i++   )
{
cout   < <   "Input   str[ "   < <   i   < <   "]: ";
cin   > >   str[i];
}

for   (   i   =   0;   i   <   10;   i++   )
{
for   (   j   =   i   +   1;   j   <   10;   j++)
{
if   (   str[i]   >   str[j]   )
{
*p   =   str[i];
str[i]   =   str[j];
str[j]   =   *p;
}
}
}

cout   < <   "Now   the   strings   are: "   < <   endl;

for   (   i   =   0;   i   <   10;   i++   )
{
cout   < <   str[i]   < <   endl;
}

return   0;
}

[解决办法]
p初值为空,不能用他来接收。
可以
string pstr;
string *p=&pstr;
然后就对了。

热点排行