Can you help me please?

I have a Car.sln file visual studio 2012 prof. This has Car.h, Stdafx.h, targetver.h as header files. Source files are automobile.cpp, Car.cpp, stdafx. cpp. I spent two days writing this but have no idea why I get these particular error messages. Please help.

below is the main module, automobile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "stdafx.h"  // Defines IDE required external definition files
#include <iostream>  // Defines objects and classes used for stream I/O
// Class Definition header file(s)
#include "Car.h"
#include <string.h>

// Namespaces utilized in this program
using namespace std; // Announces to the compiler that members of the namespace "std"
                     // are utilized in this program

int main()          
{
	  
 
 char selection; //Menu selection
  
 Car CCar;

 
 
// cout << "The speed of the SUV is set to: " << Speed <<endl;
// Car first( 2007, "GMC", Speed);
 
 	//Display the menu and get a valid selection
 	do
 	{
 		CCar.displayMenu();
 		cin >> selection;
 		while(toupper(selection) < 'A' || toupper(selection) > 'C')
 		{
 			cout << "Please make a choice of A or B or C:";
 			cin >> selection;
 		}
 
 	//Process the user's menu selection
 		{
 			switch (selection)
 			{
 			case 'a':
 			case 'A': cout << "Acceleration Selected ";
 				cout << CCar.Accelerate() << endl;
 			break;
 			case 'b':
 		case 'B': cout << "Brake Selected";
 			cout << CCar.Brake()  << endl;
 			break;
 			}
 		}while (toupper(selection) != 'C');

	// This prevents the Visual Studio 2012 Console Window from closing during
	// debug mode and allows you to select and copy the results displayed in
	// the Console window.
	cout << endl;  // Inserts a blank line before the prompt occurs
	system("pause");

	return 0;
}



below is Car.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

  
class Car
{
	// Public Interface

private:
	 

	//  Variable Declarations
	int YearModel, Speed=0;
	std::string Make;


public:
	// Class Constructor(s)
	Car( );

	//Client Methods
	string getMake();
    int getModel();
    int getSpeed();
    void Accelerate();
 	void Brake();
 	void displayMenu();

	// Class Destructor
	~Car(void);


};



below is Car.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
#include "Car.h"  // Class Definition file
#include <stdio.h>
#include "stdafx.h"
#include <string.h>


// Class Default Constructor

 Car::Car( )
{
    
   
 }


 //To get who makes the car. 
string Car::getMake()
{
 
 return Make;
 }

 //To get the year of the car.
 int Car::getModel()
 {
 return YearModel;
 }

 //To holds the car actual speed.
 int Car::getSpeed()
 {
 	return Speed;
 }

 //To increase speed by 5.
 
 void Car::Accelerate()
 {
 	Speed = Speed + 5;
 }
 //To drop the speed of the car by 5.
 void Car::Brake() 
 {
 	Speed = Speed - 5;
 }

void displayMenu()
{
	cout <<"\n				Menu\n";
	cout << "----------------------------\n";
    cout << "A)Accelerate the Car\n";
	cout << "B)Push the Brake on the Car\n";
	cout << "C)Exit the program\n\n";
    cout << "Enter your choice: ";
}


below is stdafx.cpp
1
2
3
4
5
6
7
8
9
// stdafx.cpp : source file that includes just the standard includes
// PROG111_ProjectTemplate.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file


below is stdafx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// 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>



// TODO: reference additional headers your program requires here


below is targetver.h
1
2
3
4
5
6
7
8
9
pragma once

// Including SDKDDKVer.h defines the highest available Windows platform.

// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#include <SDKDDKVer.h>




errors I get are:
Car.cpp: 'cout' undeclared identifier (this is strange since this is a built in function)
Car.cpp: 'Speed' undeclared identifier (why since this is declared in header file)
Car.cpp: 'Car' is not a class or namespace name
Car.cpp: 'YearModel' is undeclared identifier
Car.cpp: missing type specifier - int assumed. Note: C++ doesn't support default-int. (several of this)

automobile.cpp: fatal error, end of file found before the left brace '{' 'c:\users\sang\documents\visual studio 2012\projects\car\car\automobile.cpp(49)' was matched


and then several iteration the seemingly same thing
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(695): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(742): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'

In your previous thread, you were advised that your use of precompiled headers was the reason that your header file definitions weren't being properly included. Have you resolved that?

For that matter, why are you starting a new thread, when you already have a perfectly good one asking for help with these problems?
Car.cpp: 'cout' undeclared identifier (this is strange since this is a built in function)
It is std::cout
Car.cpp: 'Speed' undeclared identifier (why since this is declared in header file)
Car.cpp: 'Car' is not a class or namespace name
Car.cpp: 'YearModel' is undeclared identifier
Car.cpp: missing type specifier - int assumed. Note: C++ doesn't support default-int. (several of this)
As MikeyBoy said turn off precompiled headers, remove include "stdafx.h" and include iostream and whichever header you need maniually.
Thanks all.

@MikeyBoy, I thought I am able to delete my other thread. I am new to this board.

if I turn off precompiled headers, many errors go away but I still have other errors. such as:

automobile.cpp: fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

(Why this program is looking for precompiled header?)

I have warnings (not errors) too such as:
automobile.cpp(39): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\sang\documents\visual studio 2012

warning C4627: '#include "Car.h"': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\sang\documents\visual studio 2012

warning C4627: '#include <string.h>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header



If anyone can shed insight to these, I appreciate it. I'm reading some c++ books but still lost.
I thought I am able to delete my other thread.

Why would you do that? When people delete the posts they've made here, it damages the value of this forum as a resource for other people.

As for the precompiled headers, that's a Visual Studio-specific feature that I don't use, so it will need someone else who's expert in them to answer your questions.
closed account (iAk3T05o)
I use visual c++ and have not recieved such errors. Did you select "Empty Project" in the setup?
Topic archived. No new replies allowed.