C++ Cpp错误,包括Visual studio 2012中的多个文件

C++ Cpp错误,包括Visual studio 2012中的多个文件,c++,C++,我已尝试在visual studio 2012上创建多个Cpp文件,我的代码部分如下: 外部测试ccp // externTest.cpp : Defines the entry point for the console application. // #include "...\externTest\externTest\write.h" ////////////////// // Global variables ///////////////// int Count = 5; /////

我已尝试在visual studio 2012上创建多个Cpp文件,我的代码部分如下:

外部测试ccp

// externTest.cpp : Defines the entry point for the console application.
//
#include "...\externTest\externTest\write.h"
//////////////////
// Global variables
/////////////////
int Count = 5;
/////////////////
// Extern functions
/////////////////
extern void write_extern ();
int main()
{
    int count = Count;
    write_extern();
    getchar ();
    return 0;
}
// write.ccp
//////////////////
// Includes
/////////////////
#include <...\externTest\externTest\write.h>
////////////////////
// Functions definition
////////////////////
void write_extern ()
{
    cout<< "Count is: \t" << count;
}
write.h

#ifndef WRITE_H
#define WRITE_H

////////////////////////
// Includes
////////////////////////
#include "stdafx.h"
#include <iostream>
using namespace std;
////////////////////////
// Variables
////////////////////////
extern int count;
////////////////////////
// Function prototype
////////////////////////
void write_extern (void);
///////////////////////
#endif // !WRITE_H
\ifndef WRITE\u H
#定义写入
////////////////////////
//包括
////////////////////////
#包括“stdafx.h”
#包括
使用名称空间std;
////////////////////////
//变数
////////////////////////
外部内部计数;
////////////////////////
//功能原型
////////////////////////
无效外部写入(无效);
///////////////////////
#endif/!写
write.cpp

// externTest.cpp : Defines the entry point for the console application.
//
#include "...\externTest\externTest\write.h"
//////////////////
// Global variables
/////////////////
int Count = 5;
/////////////////
// Extern functions
/////////////////
extern void write_extern ();
int main()
{
    int count = Count;
    write_extern();
    getchar ();
    return 0;
}
// write.ccp
//////////////////
// Includes
/////////////////
#include <...\externTest\externTest\write.h>
////////////////////
// Functions definition
////////////////////
void write_extern ()
{
    cout<< "Count is: \t" << count;
}
//write.ccp
//////////////////
//包括
/////////////////
#包括
////////////////////
//函数定义
////////////////////
无效写入外部()
{
无法将指令添加到“stdafx.h”或重新生成预编译头


最后,提前感谢您的帮助:)

您必须在项目选项中包含
stdafx.h
,或者禁用该选项。

您创建了一个使用预编译头的项目,因此编译器会在.cpp文件中查找第一个包含的#include“stdafx.h”行,您可以通过以下方式进行更改:

1) 在“解决方案”视图中的文件上单击鼠标右键,然后打开“属性”

2) 展开
C/C++
小节

3) 在
预编译头下
并将
创建/使用预编译头
设置为
不使用预编译头


或者只是创建一个空项目并将您的文件添加到其中,以最好的为准。

小备注:您有不同的
count
s:一个
count
,另一个
count
。非常感谢,这是解决方案:)