I changed the code slightly.
This won't work from main:
TicTac::board[i]
Note the other call from main:
my_game.draw_board();
This is correct. You type the name of the object (my_game), then a dot, then the function or data member (if it is public. You can't do it from main if it's private).
The slightly revised code is below:
#include<iostream>
using std::cout;
using std::cin;
char player[1];
char i[1];
class TicTac {
private:
char board[9];
public:
TicTac(); //Constructor
void draw_board();
void getmove();
bool GameOver ();
};
//Constructor
TicTac::TicTac(){
for(int i=0; i<9; i++) //initialize board to blank
board[i]=' ';
}
void TicTac::getmove ()
// assume human is player x
{
int row, col;
std::cout << "Enter row : ";
std::cin >> row;
std::cout << "Enter column : ";
std::cin >> col;
//here is a list of if statements for all the
//possible squares of the playing field a player may choose.
if (row==1 && col ==1){
board[0]= *player;}
if (row==1 && col ==2){
board[1]= *player;}
if (row==1 && col ==3){
board[2]= *player;}
if (row==2 && col ==1){
board[3]= *player;}
if (row==2 && col ==2){
board[4]= *player;}
if (row==2 && col ==3){
board[5]= *player;}
if (row==3 && col ==1){
board[6]= *player;}
if (row==3 && col ==2){
board[7]= *player;}
if (row==3 && col ==3){
board[8]= *player;}
}
void TicTac::draw_board()
{
// system("cls");
/* cout << ("_____________\n");
cout << "| %c | %c | %c |\n", board[0], board[1], board[2];
cout << "_____________\n";
cout << "| %c | %c | %c |\n", board[3], board[4], board[5];
cout << "_____________\n";
cout << "| %c | %c | %c |\n", board[6], board[7], board[8];
cout << "_____________\n";*/
cout << "|" << board[0] << "|" << board[1] << "|" << board[2] << "|\n";
}
bool TicTac::GameOver ()
{
// returns false for now, but add code to check whether game is over.
return false;
}
int main()
{
cout << "\nWelcome to Tic Tac Toe.\n";
cout << "\nThe computer player will be represented by a C.\n";
cout << "\nWhat character would you like to represent you? (Enter any letter.) ";
cin >> player;
TicTac my_game;
while(!my_game.GameOver ())
{
my_game.draw_board();
system("pause");
my_game.getmove ();
my_game.draw_board();
system ("PAUSE");
}
return 0;
}
Lines 5 and 6 - What are you declaring one element arrays instead of simple char variables?
Line 9 - made board private since you said you wanted it private. Private is default, but it never hurts to type in private explicitly.
Line 68 - I commented this line out. You can put it back in later, but for debugging purposes, it's useful to see exactly what is happening. Clearing the screen can make you miss things. Comment it out when debugging. Put it back in when it's working.
Lines 69 - 75 - it looks like you are trying to use cout the way you use printf. You can use either, but don't try to mix them.
Line 77 - One way you can use cout. Only prints the top line. Add two more lines of code to print the rest.
Line 96 - made object declaration BEFORE the loop.
Line 98 - Took out the TicTac::board line and replaced it with a new function. Right now the function is trivial. You'll need to add to it.