Visual Studios 在没有 main() 的情况下构建和调试.cpp文件

Visual Studios building and debugging .cpp file without main()

本文关键字:构建 情况下 调试 文件 cpp Studios main Visual      更新时间:2023-10-16

教授刚刚给了我们一个C ++代码块,以便了解Visual Studio中的调试窗口,但是在创建一个空白的win32控制台项目然后拖入.cpp文件后,我在尝试调试时收到丢失.exe错误消息。我到处找过,没有一个机构完全回答这个问题,我认为在这一点上,一定是代码有问题。

    // Test1.cpp : main project file.
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace System;
int accum = 0;
int sum (int x, int y)
{
  int t = x + y;
  accum += t;
  return t;
}
int calc (int op1, int op2, int opcode)
{
__asm
{
    mov ebx, opcode;
    test ebx, 0x01;
    jz sub_2;
    mov eax, op1;
    add eax, op2;
    jmp done;
sub_2:
    test ebx, 0x02;
    jz mul_3;
    mov eax, op1;
    sub eax, op2;
    jmp done;
mul_3:
done:
}
}

int main()
{
  int j = -2;
  int i = 0;
  int k = 0;
  float f = 0.0;
  char ch;
  int int_array[5];
  struct customer
  {
      char  name[20];
      short age;
      int   flag;
  };
  struct customer c[10];
  ch = 'A';
  ch |= 0x20;
  i = j * 10 / 5;
  if (i != 0)
      goto cont;
  j = i / 0;
cont: 
  i = sum ( j, -123 );
  printf("decimal = %d, hex = 0x%4xn", i, i);
  for (i = 0; i < 5; i++)
  int_array[i] = i + 100;
  switch (i) {
      case 100:
        k = k / i;
        break;
      case 200:
        k = k % i;
        break;
      case 300:
      case 400:
        k += 256;
        break;
      default:
        f = 1.0;
  }
  printf("f = %fn", f);
  strcpy(c[3].name,"Larry King");
  c[3].age  = 65;
  c[3].flag = 10;
  c[3].flag = c[3].flag << 5;
  strcpy(c[3].name,"Larry King                                ");
    k = calc(i, j, 1);
    k = calc(i, j, 2);
  return 0;
}

您的代码确实有一个 main 函数,这是它工作所必需的。

正如您所说,调试器返回了"缺少可执行文件"错误,我假设您没有编译代码,或者如果是这样,则有一些错误,可以在输出和错误窗口中找到。

如果您正在处理具有单个源文件的空白项目,我会说没有必要使用预编译的标头(它可能丢失,因此会导致错误)。

我建议您重新生成代码并重试。如果错误仍然存在,请告诉我们"输出"窗口的内容。

控制台程序必须具有 main。

相关文章: