Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with strings not wanting to work =(

Status
Not open for further replies.

BungoMan

Programmer
May 13, 2002
12
US
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 &quot;vector.h&quot;
#include &quot;matrix.h&quot;

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 << &quot;Select who will go first 'X' or 'O'&quot; << 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 << &quot;Do you wish to see an explaination of the game?&quot; << endl;
cin >> help;
getline(cin,dummy);
if (help=='y'||help=='Y'||help=='1')
{
cout << &quot;0,0#0,1#0,2\n###########\n1,0#1,1#1,2\n###########\n2,0#2,1#2,2\n&quot;;
cout << endl << &quot;This is what the board looks like initialy.&quot; << endl;
cout << &quot;To place an X or O on the board enter in the coordinates in the&quot; << endl;
cout << &quot;following format: xcoord ycoord, like this 0 1. This would place&quot; << endl;
cout << &quot;an X or O at the coordinate 0,1&quot; << 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 << &quot;Select where you wish to place an &quot; << start << endl;
else
cout << endl << &quot;Select where you wish to place an &quot; << 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) << &quot; wins the game!&quot; << endl;
break;
}
}
}

void displayboard(const matrix <char> board)
{
std::cout;
std::cin;
std::cerr;
using namespace std;
cout << &quot;board[0][0]#[0][1]#[0][2]\n###########\n[0][1]#[1][1]#[1][2]\n###########\n[0][2]#[1][2]#[2][2]\n&quot;;
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
 
string is in namespace std

Try this :
using namespace std;

Also change <vector.h> to <vector> /JOlesen
 
changed using namespace string; to using namespace std; and i got the following errors...

-------------------Configuration: TicTacToe - Win32 Debug--------------------
Compiling...
TicTacToe.cpp
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(35) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(36) : error C2872: 'cin' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(37) : error C2872: 'cin' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(37) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 ar
guments - 2 provided
c:\program files\microsoft visual studio\vc98\include\string(149) : see declaration of 'getline'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(37) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(37) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(37) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(47) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(48) : error C2872: 'cin' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(49) : error C2872: 'cin' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(49) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 ar
guments - 2 provided
c:\program files\microsoft visual studio\vc98\include\string(149) : see declaration of 'getline'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(49) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(49) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(49) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(52) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(53) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(54) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(55) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(56) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(68) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(70) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(71) : error C2872: 'cin' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(72) : error C2872: 'cin' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(72) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 ar
guments - 2 provided
c:\program files\microsoft visual studio\vc98\include\string(149) : see declaration of 'getline'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(72) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(72) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(72) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce temp
late argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(90) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(90) : error C2297: '<<' : illegal, right operand has type 'char [16]'
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(102) : error C2872: 'cout' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\My Projects\TicTacToe\TicTacToe.cpp(103) : error C2872: 'cout' : ambiguous symbol
Error executing cl.exe.

TicTacToe.exe - 31 error(s), 0 warning(s)


why would it do that??
 
I think the problem must be somewhere in matrix.h or stdafx.h.
Could you post those files ?
/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top