使用Code Blocks 编译并运行出错 什么原因

ytu_ls 2012-01-09 08:17:38
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct Point{double x,y;};
Point p[2000];
bool cmp(Point a,Point b)
{
if(a.y==b.y)
{
return a.x<b.x;
}
else return a.y>b.y;

}
bool cmp1(Point a,Point b)
{
return a.x>b.x;
}
void sort_t(Point p[],int len)
{
int yTo[2000][2];
int s,e;
double temp;
int count=0;
sort(p,p+len,cmp);
temp=p[0].y;
s=0;
yTo[count][0]=s;
for(int i=1;i<len;i++)
{
if(temp==p[i].y)
{
e=i;
yTo[count][1]=e;
}
else
{
s=i;
yTo[count++][0]=s;
temp=p[i].y;
}
}
for(int i=0;i<count;i++)
{
int j=yTo[i][0];
if(i%2==0)
{
sort(p+j,p+yTo[i][1],cmp);
}
else
{
sort(p+j,p+yTo[i][1],cmp1);
}
}
}
int main()
{
freopen("f:/in.txt","r",stdin);
freopen("f:/out.txt","w",stdout);
int count=0;
while(cin>>p[count].x>>p[count].y)
{
++count;
}
sort_t(p,count);
for(int i=0;i<count;i++)
{
cout<<p[i].x<<" "<<p[i].y<<endl;
}
return 0;
}

编译没问题 但是一运行 就会自动弹出 .exe已经停止工作 也没显示代码有错误之类 我是用CodeBlocks 运行的 运行结果如下
Compiling: F:\C++\1\1.cpp
Linking console executable: F:\C++\1\1.exe
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings

Checking for existence: F:\C++\1\1.exe
Executing: D:\Program Files\CodeBlocks/cb_console_runner.exe "F:\C++\1\1.exe" (in F:\C++\1)
Process terminated with status -1073741819 (0 minutes, 4 seconds)

哪位高手能告诉我这是什么原因
...全文
1033 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ytu_ls 2012-01-11
  • 打赏
  • 举报
回复
已经找到问题并解决了 谢谢大家的帮助
ken_scott 2012-01-10
  • 打赏
  • 举报
回复

if(i%2==0)
{
sort(p+j,p+yTo[i][1],cmp); // 在这挂了, 具体原因自己看下, 估计是越界了
}
hongwenjun 2012-01-09
  • 打赏
  • 举报
回复
freopen("f:/in.txt","r",stdin);
freopen("f:/out.txt","w",stdout);
int count=0;
while(cin>>p[count].x>>p[count].y) {
++count;
}

看的的代码 是 C 的 I/O ,又用C++ 的流 看不懂什么意思
hongwenjun 2012-01-09
  • 打赏
  • 举报
回复
我这里没有 f:/in.txt
正常执行完程序
独自听枫 2012-01-09
  • 打赏
  • 举报
回复
单步调试,看是到那一句停止的工作,一般都是内存操作异常

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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