string does not name a type

when I compile this code, it says that the string on line 25 does not name a type.

Anyone see a problem? Because I don't.

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
#ifndef GAME_H
#define GAME_H
#include <fstream>
#include "string.h"

// The "cookie" is represented as an array of int.
// Each element describes a row of the cookie.
//   -- If cookie[i] == j, that means that there are
//        j columns left in row i of the cookie


const int MAXROWS = 10;

// Number of rows currently remaining in the cookie
int numberOfRows;

// Number of columns currently remaining in the cookie
int numberOfColumns;

// The cookie.  If cookie[i] == j, then the cookie currently
// has crumbs filling the j columns at row i
int cookie[MAXROWS];
int initialNumberOfRows;

string humanPlayerName;
int nGamesWonByComputerPlayer;
int nGamesWonByHumanPlayer;

// Check a proposed move to see if it is legal.
// A legal move must bite at least one remaining crumb.
bool biteIsLegal (int column, int row);
void displayCookie(std::ostream& output);
bool gameEnded();
bool isADangerousMove (int column, int row);
void printRules();
void printScore();
void startAGame();
void takeABite (int column, int row);
void playAGame();

#endif 
First, strings are in the std namespace, just like ostreams.

Second, I don't see <string> included anywhere. :)

-Albatross
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
#ifndef GAME_H
#define GAME_H
#include <fstream>
#include <string> //THIS

const int MAXROWS = 10;

int numberOfRows;

int numberOfColumns;

int cookie[MAXROWS];
int initialNumberOfRows;

std::string humanPlayerName; // std::, or using namespace std;, or using std::string;
int nGamesWonByComputerPlayer;
int nGamesWonByHumanPlayer;

bool biteIsLegal (int column, int row);
void displayCookie(std::ostream& output);
bool gameEnded();
bool isADangerousMove (int column, int row);
void printRules();
void printScore();
void startAGame();
void takeABite (int column, int row);
void playAGame();

#endif  
Topic archived. No new replies allowed.