stdafx. h library error

Asked

Viewed 800 times

2

Does anyone know why there’s a mistake in this library and how to fix it?

This is stated in the codeblocks header:

#include "stdafx.h"
#include <windows.h>

#define TAM_PILHA 2
#define NUM_ENTRA 5

void empilha(int *pilha, int *topo, int valor)
{
if (*topo < TAM_PILHA)
{
    pilha[*topo] = valor;
    (*topo)++;
}
else
{
    printf("Pilha Cheia\n");
}
}

int desempilha(int *pilha, int *topo)
{
if (*topo > 0)
{
    (*topo)--;
    return pilha[*topo];
}
else
{
    printf("Pilha Vazia\n");
}
}

int main()
{
int pilha_par[TAM_PILHA], pilha_impar[TAM_PILHA], topo_par = 0, topo_impar = 0;
int i = 0, num_do_usuario = 0;
for (i = 0; i < NUM_ENTRA; i++)
{
    printf("\nEntre com um numero: ");
    scanf("%d", &num_do_usuario);

    if ((num_do_usuario % 2) == 0)
    {
        empilha(pilha_par, &topo_par, num_do_usuario);
    }
    else
    {
        empilha(pilha_impar, &topo_impar, num_do_usuario);
    }

}

printf("\n\nNumeros pares sao: ");
while (topo_par > 0)
{
    printf("%d ", desempilha(pilha_par, &topo_par));
}

printf("\n\nNumeros impares sao: ");
while (topo_impar > 0)
{
    printf("%d ", desempilha(pilha_impar, &topo_impar));
}

printf("\n\n");

system("pause");
return 0;
}

Error appears:

fatal error: stdafx.h: No such file or directory|
  • 4

    Places which error appears.

  • Enter your complete code, this error may have several causes. stdafx.h is a header precompiled from the visual studio, there are cases that do not need it, sometimes it is necessary to include windows.h. I can’t say without seeing the full code.

  • I’ve already put the entire code in there for analysis.

  • 1

    This header is generated by VS, if you open it you will see that it contains other statements of headers, serves only as "shortcut", can add its contents directly in your project.

1 answer

2


stdafx.h is used by the Visual Studio implementation of pre-compiled headers. In many cases this can be avoided, especially if your project is small and with few dependencies.

To resolve you can copy the file stdafx.h from the Visual Studio project folder to the codeblocks project folder and try to compile.

I took the test here, withdrawing:

#include "stdafx.h"
#include <windows.h>

and including #include <stdio.h>, worked normally.

In case you still can’t solve your problem, have this Code::Blocks forum about your doubt.

  • 1

    Solved even, it is very boring the VS, CB much better for this language, my opinion, more intuitive. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.