how to compile this logic in visual C++ express 2010

Go To StackoverFlow.com

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 ==========
2012-04-03 21:27
by user948950


4

In your project settings, turn off precompiled headers. This has been turned on when you created the project (probably by default) and it's expecting #include "StdAfx.h" to be the first line of your file.

2012-04-03 21:31
by Lou


2

After fixing simple typos and actually reading the error message..:

#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-03 21:29
by ildjarn


1

Set up the project as a Blank Win32 Console Application. Add in your source code and compile. It should work then.

Or you can just add in the file it was asking for: Did you forget to add '#include "StdAfx.h"' to your source? as per the error report.

2012-04-03 21:29
by jakebird451
Ads