Thread: doesn't recognize stdafx.h

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    12

    doesn't recognize stdafx.h

    i am a student taking c++ so i do not know that much about it yet.
    but we had a homework assignment that i wrote code for but the first error i get is that is doesn't recognize stdafx.h when i try to include it here is the code can anyone help? i am using microsoft visual c++ 2008 express edition.
    Code:
    #include "stdafx.h"
    #include <iostream>;
    
    using namespace std;
    
    using namespace System;
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int city1 = 0;
    	int city2 = 0; 
    	int averageTemp= 0; 
    	cout << "Enter the name of city 1:";
    	cin >> city1
    	cout << "Enter the name of city 2:";
    	cin >> city2
        averageTemp = (city1 * city2)/2
    	cout << "the average temperature of the two cities is " << averageTemp << endl;
    
    	return 0;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    stdafx.h is not a "standard" file (despite its name). It is produced by Visual Studio when you set up a project.

    If you are not compiling your code within a project set up by VS, then it won't have such a file. Either remove it or make an empty file with that name.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    ok i got tht to work ow it doesn't recgonize the namespace System

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by GiantFurby View Post
    ok i got tht to work ow it doesn't recgonize the namespace System
    System is not a standard namespace, so I'm not sure how you expect it to recognize it. Seeing as your code doesn't appear to use anything beyond what is in the std namespace, I don't see a problem with removing that line altogether.

    You also don't need a semicolon after #include.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    got it working.
    thank you!!!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stdafx.h and the FreeType library
    By Mastadex in forum Windows Programming
    Replies: 1
    Last Post: 11-23-2007, 01:36 PM
  2. stdafx.h
    By beene in forum Windows Programming
    Replies: 7
    Last Post: 10-15-2006, 10:25 AM
  3. stdafx.h question
    By ssjnamek in forum C++ Programming
    Replies: 5
    Last Post: 08-12-2005, 11:31 PM
  4. Replies: 3
    Last Post: 11-30-2001, 07:38 PM
  5. How to recognize <Enter> with getline()?
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 11-10-2001, 06:21 PM