Start by sorting out your indentation - that may help you work out what the problem is.
When I see code like this:
while (co11!=row2)
{
cout << "Sorry! Column of matric A is not equal to row of matrix B.";
cout << "Please enter rows and columns for matrix A: ";
cin >> row1 >> co11;
cout << "Please enter rows and column for the maxtrix B: ";
cin >> row2 >> co12; }
And this:
for(i = 0; i < row1; ++i)
for(j = 0; j < co11; ++j)
{
cout << "Enter element A" << i + 1 << j + 1 << " : ";
cin >> A[i][j];
}
And this:
for(i = 0; i < row1; ++i)
{
for(j = 0; j < co11; ++j)
cout << A[i][j] << " ";
cout << endl;
myfile << A[i][j] << " ";
myfile << endl;
}
And this:
for(i = 0; i < row2; ++i)
{
for(j = 0; j < co12; ++j)
cout << B[i][j] << " ";
myfile << B[i][j] << " ";
myfile << endl;
}
It's pretty obvious that the code wasn't thought about too hard before hitting the keyboard, and that it's not obvious that what you are actually doing is right.
Sort out your indentation, add "{" and "}" even for single line blocks and then look at your code carefully to see what you end up with.
For example, this code:
for(i = 0; i < row2; ++i)
{
for(j = 0; j < co12; ++j)
cout << B[i][j] << " ";
myfile << B[i][j] << " ";
myfile << endl;
}
Is actually this:
for(i = 0; i < row2; ++i)
{
for(j = 0; j < co12; ++j)
{
cout << B[i][j] << " ";
}
myfile << B[i][j] << " ";
myfile << endl;
}
But that's not obvious from the original, and probably isn't what you wanted!