VS 2008 is "stdafx.h" a nucence?

I hawe a qustion and i hope you guys can help me out just starting out whit C++.
I wase working on: http://www.learncpp.com/cpp-tutorial/111-comprehensive-quiz/

And it came a long a litel snag.

Here is the code.

main\calc3.cpp:
1
2
3
4
5
6
7
8
9
10
#include "stdafx.h"
#include "io.h"

int main()
{
    int x = ReadNumber();
    int y = ReadNumber();
    WriteAnswer(x+y);
    return 0;
}

io.h:
1
2
3
4
5
6
7
#ifndef IO_H
#define IO_H

int ReadNumber();
void WriteAnswer(int x);

#endif 

io.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "stdafx.h"
#include <iostream>

int ReadNumber()
{
    using namespace std;
    cout << "Enter a number: ";
    int x;
    cin >> x;
    return x;
}

void WriteAnswer(int x)
{
    using namespace std;
    cout << "The answer is " << x << endl;
}

This whoden work if i dident add #include "io.h" to the "stdafx.h" file.

1
2
3
4
5
6
7
8
9
10
11
12
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

#include "io.h"
// TODO: reference additional headers your program requires here 

As you probely already guest i`am using VS C++ Express.
So if i where using a difrent IDE like CodeBlocks ore some other IDE.
Whode i stile get the same "problem" ?

Sorry for my bad gramma.
And Thanks to all that takes the time.
Last edited on
closed account (zb0S216C)
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
// io.h

#ifndef IO_H
#define IO_H

#include <stdio.h>
#include <tchar.h>
#include "targetver.h"

// Function prototypes here...

#endif  


1
2
3
4
5
6
7
// io.cpp

#include <iostream>
#include "io.h"

// The rest of you're code here...


1
2
3
4
5
6
// main\calc3.cpp

#include "io.h"

// The rest of you're code here....


After, remove the "stdafx.h" header from you're project.

This "should" cancel out the "stdafx.h" header.

In Code::Blocks, you start with an empty project. In Visual C++( Express ), the headers and source code files that are included, are optional.
Topic archived. No new replies allowed.