C/C++ - 在Visual Studio C++

问题描述:

我是一名计算机专业的学生,​​最近学会了一对情侣在网络搜索,我想出了这个代码后使用C. 中断中断工作:C/C++ - 在Visual Studio C++

#include <stdio.h> 
#include <dos.h> 
#include <conio.h> 

#ifdef __cplusplus 

    #define __CPPARGS ... 

#else 

    #define __CPPARGS 

#endif 

#define INTR 0x1c 
#define gotoxy(x,y) printf("\033[%d;%dH", (x), (y)) 
//#define clear() printf("\033[H\033[J"); 
/* 
//positioning 
void gotoxy(int x, int y) 
{ 
    printf("%c[%d;%df",0x1B,y,x); 
} 
*/ 

void interrupt handler(__CPPARGS); 
void interrupt (*oldhandler)(__CPPARGS); 

int countS = 0; 
int s = 0; 
int m = 0; 
int ms = 0; 
int l = 0; 
int flag = 0; 

int main(void) 
{ 
    clrscr(); 
    printf("%02d:%02d:%02d",m,s,ms); 
    oldhandler = getvect(INTR); 

    setvect(INTR, handler); 
    char c; 

    while(1) 
    { 
     c = getch(); 

     switch(c){ 

      case 'e': 
       goto exit_loop; 
       break; 

      case ' ': 
       flag = 1-flag; 
       break; 

      case 'r': 
       flag = s = m = ms = l = 0; 
       clrscr(); 
       printf("%02d:%02d:%02d",m,s,ms); 
       break; 

      case 'l': 
       gotoxy(++l,0); 
       printf("%02d:%02d:%02d",m,s,ms); 
       break; 
     } 
    } 

    exit_loop:; 
    setvect(INTR, oldhandler); 
    return 0; 
} 

void interrupt handler(__CPPARGS) 
{ 

    if(flag == 1){ 

     countS++; 
     ms += 55; 

     if(countS == 18) 
     { 
      countS = ms = 0; 
      s++; 

      if(s==60) 
      { 
       m++; 
       s = 0; 
      } 
     } 

     gotoxy(0,0); 
     printf("%02d:%02d:%02d",m,s,ms); 
    } 
} 

这个代码是某种用C控制台应用程序和它的历史的Turbo C++工作完美秒表。 我改变了我的IDE现在使用Visual Studio 2013年,当我在Visual C++一个新的项目 - > win32ConsoleApplication并在主文件中粘贴此代码。它不工作。那么错误说我应该在我的第一个文件中添加#include "stdafx.h"。这样做之后,这是我的主要错误列表:

Error 1 error C2146: syntax error : missing ';' before identifier 'handler' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1 
Error 2 error C2182: 'interrupt' : illegal use of type 'void' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1 
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1 
Error 4 error C2065: 'oldhandler' : undeclared identifier c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 6 error C2086: 'int interrupt' : redefinition c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 7 error C2143: syntax error : missing ';' before '(' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 8 error C2059: syntax error : ')' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 9 error C2059: syntax error : ';' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1 
Error 10 error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 44 1 ConsoleApplication1 
Error 11 error C2065: 'oldhandler' : undeclared identifier c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46 1 ConsoleApplication1 
Error 12 error C3861: 'getvect': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46 1 ConsoleApplication1 
Error 13 error C3861: 'setvect': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 48 1 ConsoleApplication1 
Error 14 error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 67 1 ConsoleApplication1 

这些错误都与这些行:

void interrupt handler(__CPPARGS); 
void interrupt (*oldhandler)(__CPPARGS); 

和使用:clrscr();

我操作的系统是windows 10-64bit并且它是我第一次在visual studio中用c/C++编程。我在Turbo C++和devC++中做过一些,但只有Turbo C++运行这个例子,甚至不是devC++。什么是diffrenses,我应该如何解决这个问题? 感谢

+1

MS-DOS已死。 –

+2

MS-DOS仍然死机。我们杀了它。我们应该如何安慰自己,所有杀人犯的凶手?世界上所拥有的最神圣和最强大的东西已经在我们的刀下流血而死:谁会把这些血从我们身上抹去? –

+0

MS-DOS已死:首先。毫无疑问,无论如何。其埋葬登记簿由牧师,文员,承办人和主要哀悼者签署。 Windows签署了它。而且Windows的名字对于改变,对于它选择的任何东西都很有帮助。 – user4581301

您在64位长的模式下工作,所以你不必访问实模式BIOS中断或MS-DOS服务。你的代码有许多其他问题,但底线是没有16位编译器和仿真器(如64位Windows上没有的NTVDM)就无法工作

+0

所以你的意思是我不能在Visual Studio解决这个问题或者我应该安装一些其他插件或编译器呢?我现在应该怎么做?有没有任何现代的IDE可以作为涡轮C + +没有任何问题? –

+0

@ mohammadfallah.rasoulnejad您需要安装像DOSBox或emu8086这样的8086模拟器,并将代码写入其中的编译器 - 在64位操作系统中无法模拟16位实模式。请参阅http://wiki.osdev.org/Real_Mode –