ok i know this is really dumb but im trying to make a tic tac toe game (using matrices, which work, so thats not the problem) and i need to use a string or two here and there, and it doesnt wanna let me use em =/, here is the code for the game itself (even though i prolly dont need to include it in this case...) and below that are the errors i get when building
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <ctime>
#include <string>
#include "vector.h"
#include "matrix.h"
using namespace string;
void displayboard(const matrix <char> board);
bool checkboard(const matrix <char> board,const char current);
int isodd(const int &check);
int iseven(const int &check);
void main()
{
//srand((unsigned)time(NULL));
matrix <char> board;
board.resize(3,3);
bool valid;
bool win;
int r,c;
int x,y;
char start=' ';
char second=' ';
char help;
string dummy;
while (start!='X'&&start!='x'&&start!='O'&&start!='o')
{
cout << "Select who will go first 'X' or 'O'" << endl;
cin >> start;
getline(cin,dummy);
}
if (start=='x'||start=='X')
start='X';
if (start=='o'||start=='O')
start='O';
if (start=='X')
second='O';
else
second='X';
cout << "Do you wish to see an explaination of the game?" << endl;
cin >> help;
getline(cin,dummy);
if (help=='y'||help=='Y'||help=='1')
{
cout << "0,0#0,1#0,2\n###########\n1,0#1,1#1,2\n###########\n2,0#2,1#2,2\n";
cout << endl << "This is what the board looks like initialy." << endl;
cout << "To place an X or O on the board enter in the coordinates in the" << endl;
cout << "following format: xcoord ycoord, like this 0 1. This would place" << endl;
cout << "an X or O at the coordinate 0,1" << endl;
}
for (r=0;r<board.numrows();r++)
for (c=0;c<board.numcols();c++)
board[r][c]=' ';
displayboard(board);
for (int a=1;a<=9;a++)
{
valid=false;
while (!valid)
{
if (isodd(a))
cout << endl << "Select where you wish to place an " << start << endl;
else
cout << endl << "Select where you wish to place an " << second << endl;
cin >> x >> y;
getline(cin,dummy);
if ((x<0||x>2||y<0||y>2))
valid=false;
else
{
for (r=0;r<board.numrows();r++)
for (c=0;c<board.numcols();c++)
if (board[r][c]==' ')
valid=true;
else
valid=false;
}
}
board[x][y]=(isodd(a))?(start)second);
displayboard(board);
win=checkboard(board,(isodd(a))?(start)second));
if (win)
{
cout << endl << (isodd(a))?(start)second) << " wins the game!" << endl;
break;
}
}
}
void displayboard(const matrix <char> board)
{
std::cout;
std::cin;
std::cerr;
using namespace std;
cout << "board[0][0]#[0][1]#[0][2]\n###########\n[0][1]#[1][1]#[1][2]\n###########\n[0][2]#[1][2]#[2][2]\n";
cout << endl;
}
bool checkboard(const matrix <char> board,const char current)
{
bool win=false;
// std::cout;
// std::cin;
// std::cerr;
if (board[0][0]==current&&board[0][1]==current&&board[0][2]==current)
win=true;
if (board[1][0]==current&&board[1][1]==current&&board[1][2]==current)
win=true;
if (board[2][0]==current&&board[2][1]==current&&board[2][2]==current)
win=true;
if (board[0][0]==current&&board[1][0]==current&&board[2][0]==current)
win=true;
if (board[0][1]==current&&board[1][1]==current&&board[2][1]==current)
win=true;
if (board[0][2]==current&&board[1][2]==current&&board[2][2]==current)
win=true;
if (board[0][0]==current&&board[1][1]==current&&board[2][2]==current)
win=true;
if (board[0][2]==current&&board[1][1]==current&&board[2][0]==current)
win=true;
return win;
}
int isodd(const int &check)
{
if (check%2==1)
return 1;
else
return 0;
}
int iseven(const int &check)
{
if (check%2==0)
return 1;
else
return 0;
}
--------------------Configuration: TicTacToe - Win32 Debug--------------------
Compiling...
TicTacToe.cpp
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(10) : error C2871: 'string' : does not exist or is not a namespace
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(33) : error C2065: 'string' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(33) : error C2146: syntax error : missing ';' before identifier 'dummy'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(33) : error C2065: 'dummy' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(38) : error C2065: 'getline' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(91) : error C2297: '<<' : illegal, right operand has type 'char [16]'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(103) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(104) : error C2872: 'cout' : ambiguous symbol
Error executing cl.exe.
TicTacToe.exe - 8 error(s), 0 warning(s)
ive tried commenting out the using namespace string; line (i only have it cause i swear i read somewhere it was necessary in vc++... maybe i read wrong...) and i still get similar errors
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <ctime>
#include <string>
#include "vector.h"
#include "matrix.h"
using namespace string;
void displayboard(const matrix <char> board);
bool checkboard(const matrix <char> board,const char current);
int isodd(const int &check);
int iseven(const int &check);
void main()
{
//srand((unsigned)time(NULL));
matrix <char> board;
board.resize(3,3);
bool valid;
bool win;
int r,c;
int x,y;
char start=' ';
char second=' ';
char help;
string dummy;
while (start!='X'&&start!='x'&&start!='O'&&start!='o')
{
cout << "Select who will go first 'X' or 'O'" << endl;
cin >> start;
getline(cin,dummy);
}
if (start=='x'||start=='X')
start='X';
if (start=='o'||start=='O')
start='O';
if (start=='X')
second='O';
else
second='X';
cout << "Do you wish to see an explaination of the game?" << endl;
cin >> help;
getline(cin,dummy);
if (help=='y'||help=='Y'||help=='1')
{
cout << "0,0#0,1#0,2\n###########\n1,0#1,1#1,2\n###########\n2,0#2,1#2,2\n";
cout << endl << "This is what the board looks like initialy." << endl;
cout << "To place an X or O on the board enter in the coordinates in the" << endl;
cout << "following format: xcoord ycoord, like this 0 1. This would place" << endl;
cout << "an X or O at the coordinate 0,1" << endl;
}
for (r=0;r<board.numrows();r++)
for (c=0;c<board.numcols();c++)
board[r][c]=' ';
displayboard(board);
for (int a=1;a<=9;a++)
{
valid=false;
while (!valid)
{
if (isodd(a))
cout << endl << "Select where you wish to place an " << start << endl;
else
cout << endl << "Select where you wish to place an " << second << endl;
cin >> x >> y;
getline(cin,dummy);
if ((x<0||x>2||y<0||y>2))
valid=false;
else
{
for (r=0;r<board.numrows();r++)
for (c=0;c<board.numcols();c++)
if (board[r][c]==' ')
valid=true;
else
valid=false;
}
}
board[x][y]=(isodd(a))?(start)second);
displayboard(board);
win=checkboard(board,(isodd(a))?(start)second));
if (win)
{
cout << endl << (isodd(a))?(start)second) << " wins the game!" << endl;
break;
}
}
}
void displayboard(const matrix <char> board)
{
std::cout;
std::cin;
std::cerr;
using namespace std;
cout << "board[0][0]#[0][1]#[0][2]\n###########\n[0][1]#[1][1]#[1][2]\n###########\n[0][2]#[1][2]#[2][2]\n";
cout << endl;
}
bool checkboard(const matrix <char> board,const char current)
{
bool win=false;
// std::cout;
// std::cin;
// std::cerr;
if (board[0][0]==current&&board[0][1]==current&&board[0][2]==current)
win=true;
if (board[1][0]==current&&board[1][1]==current&&board[1][2]==current)
win=true;
if (board[2][0]==current&&board[2][1]==current&&board[2][2]==current)
win=true;
if (board[0][0]==current&&board[1][0]==current&&board[2][0]==current)
win=true;
if (board[0][1]==current&&board[1][1]==current&&board[2][1]==current)
win=true;
if (board[0][2]==current&&board[1][2]==current&&board[2][2]==current)
win=true;
if (board[0][0]==current&&board[1][1]==current&&board[2][2]==current)
win=true;
if (board[0][2]==current&&board[1][1]==current&&board[2][0]==current)
win=true;
return win;
}
int isodd(const int &check)
{
if (check%2==1)
return 1;
else
return 0;
}
int iseven(const int &check)
{
if (check%2==0)
return 1;
else
return 0;
}
--------------------Configuration: TicTacToe - Win32 Debug--------------------
Compiling...
TicTacToe.cpp
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(10) : error C2871: 'string' : does not exist or is not a namespace
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(33) : error C2065: 'string' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(33) : error C2146: syntax error : missing ';' before identifier 'dummy'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(33) : error C2065: 'dummy' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(38) : error C2065: 'getline' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(91) : error C2297: '<<' : illegal, right operand has type 'char [16]'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(103) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(104) : error C2872: 'cout' : ambiguous symbol
Error executing cl.exe.
TicTacToe.exe - 8 error(s), 0 warning(s)
ive tried commenting out the using namespace string; line (i only have it cause i swear i read somewhere it was necessary in vc++... maybe i read wrong...) and i still get similar errors