0

I have C++ code from a book and would like to run it in visual C++ express 2010 but I got an error like following. Could you tell me how to run this code ? Thank you so much !

#include <iostream>

class Cat
{
public:
int itsAge;
int itsWeight;
};

int main()
{
Cat Frisky;
Frisky.itsAge = 5;
std::count << "Frisky is a cat who is ";
std::count << Frisky.itsAge << " years old.\n";

reutrn 0;
}
 ------ Build started: Project: chp6, Configuration: Debug Win32 ------
  list6_1.cpp
  list6_1.cpp(2): warning C4627: '#include <iostream>': skipped when looking for          precompiled header use
            Add directive to 'StdAfx.h' or rebuild precompiled header
  list6_1.cpp(20): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
   ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
4

3 回答 3

4

在您的项目设置中,关闭预编译头文件。这在您创建项目时已打开(可能默认情况下),它预计#include "StdAfx.h"是您文件的第一行。

于 2012-04-03T21:31:15.023 回答
2

在修复了简单的错别字并实际阅读了错误消息之后..:

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

class Cat
{
public:
    int itsAge;
    int itsWeight;
};

int main()
{
    Cat Frisky;
    Frisky.itsAge = 5;
    std::cout << "Frisky is a cat who is ";
    std::cout << Frisky.itsAge << " years old.\n";

    return 0;
}
于 2012-04-03T21:29:50.427 回答
1

将项目设置为空白 Win32 控制台应用程序。添加你的源代码并编译。它应该工作。

或者您可以添加它要求的文件:Did you forget to add '#include "StdAfx.h"' to your source?根据错误报告。

于 2012-04-03T21:29:38.197 回答