qq_32756899 2016-05-05 10:15 采纳率: 0%
浏览 2399

C++编译通过但是cmd窗口不显示程序直接退出了

应该跟添加getchar() system(“pause”)什么的没有关系

 //MyRectangle.h
#pragma once
#include"Screen.h"
class MyRectangle
{
public:
 MyRectangle();
 MyRectangle(int x1, int y1, int x2, int y2, Screen* screen);
 void setCoordinations(int x1, int y1, int x2, int y2);
 void setScreen(Screen& screen);
 void Draw();
private:
 int x1_;
 int x2_;
 int y1_;
 int y2_;
 Screen* screen_;
};

//Screen.h
#pragma once
class Screen
{
public:
 void exitWhenInvalidScreen(int x, int y);
 int getWidth();
 int getHeight();
 int setWidth(int width);    //return width
 int setHeight(int height);  //return height
 Screen();
 Screen(int, int);
 //~Screen();
private:
 int width;
 int height;
};

//main.cpp
#include<iostream>
#include"Screen.h"
#include"MyRectangle.h"
using namespace std;
int main()
{
 int width,height;
 cin>>width>>height;
 Screen screen(width,height);
 int leftX,leftY,rightX,rightY;
 cin>>leftX>>leftY>>rightX>>rightY;
 MyRectangle myRectangle1(leftX, leftY, rightX, rightY, &screen);
 MyRectangle *myRectangles=new MyRectangle[2];
 myRectangles[1].setCoordinations(10, 300, 700, 500);
 myRectangles[1].setScreen(screen);
 myRectangle1.Draw();
 for (int i = 0; i<2; i++) {
  myRectangles[i].setScreen(screen);
  (myRectangles + i)->Draw();
 }

 delete[]myRectangles;

#ifdef DEBUG
 stdcin.get();
#endif
 system("pause");
 return 0;
} 
//MyRectangle.h

#pragma once
#include"Screen.h"
class MyRectangle
{
public:
 MyRectangle();
 MyRectangle(int x1, int y1, int x2, int y2, Screen* screen);
 void setCoordinations(int x1, int y1, int x2, int y2);
 void setScreen(Screen& screen);
 void Draw();
private:
 int x1_;
 int x2_;
 int y1_;
 int y2_;
 Screen* screen_;
};




//Screen.h

#pragma once
class Screen
{
public:
 void exitWhenInvalidScreen(int x, int y);
 int getWidth();
 int getHeight();
 int setWidth(int width);    //return width
 int setHeight(int height);  //return height
 Screen();
 Screen(int, int);
 //~Screen();
private:
 int width;
 int height;
};




//main.cpp

#include<iostream>
#include"Screen.h"
#include"MyRectangle.h"
using namespace std;
int main()
{
 int width,height;
 cin>>width>>height;
 Screen screen(width,height);
 int leftX,leftY,rightX,rightY;
 cin>>leftX>>leftY>>rightX>>rightY;
 MyRectangle myRectangle1(leftX, leftY, rightX, rightY, &screen);
 MyRectangle *myRectangles=new MyRectangle[2];
 myRectangles[1].setCoordinations(10, 300, 700, 500);
 myRectangles[1].setScreen(screen);
 myRectangle1.Draw();
 for (int i = 0; i<2; i++) {
  myRectangles[i].setScreen(screen);
  (myRectangles + i)->Draw();
 }




 delete[]myRectangles;




#ifdef DEBUG
 stdcin.get();
#endif
 system("pause");
 return 0;
}



//MyRetangle.cpp

#include"MyRectangle.h"
#include"Screen.h"
#include<iostream>
#include<graphics.h>
MyRectangle::MyRectangle()
{
 x1_ = 0; y1_ = 0; x2_ = 0; y2_ = 0;
 std::cout << "myrectangle" << std::endl;
}
MyRectangle::MyRectangle(int x1, int y1, int x2, int y2, Screen* screen)
{
 x1_ = x1;
 x2_ = x2;
 y1_ = y1;
 y2_ = y2;
 screen_ = screen;
 std::cout << "myrectangle" << std::endl;
}
void MyRectangle::setCoordinations(int x1, int y1, int x2, int y2)
{
 x1_ = x1;
 x2_ = x2;
 y1_ = y1;
 y2_ = y2;
}
void MyRectangle::setScreen(Screen& screen)
{
 screen_ = &screen;
}
void MyRectangle::Draw()
{
 if ((x1_ <= 0) || (x2_ <= 0) || (y1_ <= 0) || (y2_ <= 0) || (x2_ - x1_)>(*screen_).getWidth() || (y2_ - y1_)>(*screen_).getHeight())
 {
  std::cout << "invalid myrectangle" << std::endl;
 }
 else
 {
  rectangle(x1_, y1_, x2_, y2_);
  std::cout << x1_ << ' ' << y1_ << ' ' << x2_ - x1_ << ' ' << y2_ - y1_ << std::endl;
 }
}



//Screen.cpp

#include"Screen.h"
#include<iostream>
#include<cstdlib>
#include<graphics.h>
using namespace std;
Screen::Screen()
{
 width = 640;
 height = 480;
 initgraph(width, height);
 std::cout << "screen" << std::endl;
}
Screen::Screen(int x, int y)
{
 width = x;
 height = y;
 exitWhenInvalidScreen(x, y);
 initgraph(width, height);
 std::cout << "screen" << std::endl;
}
/*Screen::~Screen()
{
getchar();
cout << "折构函数已启用";
closegraph();
}*/




int Screen::getWidth()
{
 return width;
}
int Screen::getHeight()
{
 return height;
}
int Screen::setWidth(int w)
{
 width = w;
 exitWhenInvalidScreen(width, 500);
 return width;
}
int Screen::setHeight(int h) //return height
{
 height = h;
 exitWhenInvalidScreen(500, height);
 return height;
}
void Screen::exitWhenInvalidScreen(int x, int y)
{
 if (!((x > 0 && x <= 1000) && (y > 0 && y <= 1000)))
 {
  std::cout << "invalid screen size";
  exit(0);
 }
}

其中跟graph有关的函数EGE图形库中的,应该没什么问题。用的是VS2013
新手一枚 望不吝指教-。-
“图图.exe”(Win32): 已加载“F:\C++\图图\Debug\图图.exe”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\ntdll.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\kernel32.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\KernelBase.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\imm32.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\user32.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\gdi32.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\msvcr120d.dll”。无法查找或打开 PDB 文件。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\msvcp120d.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\ole32.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\msimg32.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.10586.20_none_22adb5eaa762c7fa\GdiPlus.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\combase.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\msvcrt.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\rpcrt4.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\sspicli.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\cryptbase.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\bcryptprimitives.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\sechost.dll”。已加载符号。
“图图.exe”(Win32): 已加载“C:\Windows\SysWOW64\oleaut32.dll”。已加载符号。
线程 0x2360 已退出,返回值为 0 (0x0)。
线程 0x12cc 已退出,返回值为 0 (0x0)。
线程 0x1898 已退出,返回值为 0 (0x0)。
程序“[7540] 图图.exe”已退出,返回值为 0 (0x0)。

  • 写回答

2条回答 默认 最新

  • K.I.S.S. 2016-05-06 00:19
    关注

    很简单的问题 你按的是F5吧,F5是调试,如果调试不存在错误就会退出

    想cmd窗口不消失,按ctrl+f5就好,

    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制