关于C++ vector输入矩阵

代码如下:#include<iostream>#include<vector>usingnamespacestd;intmain(){typedefvector<vect... 代码如下:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
typedef vector<vector<int>> T1,T2;
vector<int>T3;
int row1,col1,row2,col2,n;
cout<<"Enter the row and column: ";
cin>>row1>>col1;
int a,i;
cout<<"Enter the first matrix:"<<endl;
for(i=0;i<row1;i++)
{
cin>>a;
while(a>=0)
{
T3.push_back(a);
cin>>a;
}
T1[i].push_back(T3);
}
system("pause");
}
其实是想输入行和列来动态分配的, 目前报错是:
错误 1 error C2143: syntax error : missing ';' before '[' d:\11\two matrix\two matrix\code.cpp 22
错误 2 error C2337: 'i' : attribute not found d:\11\two matrix\two matrix\code.cpp 22
错误 3 error C2143: syntax error : missing ';' before '.' d:\11\two matrix\two matrix\code.cpp 22
可是感觉分号没有少啊,不知道为什么。而且在此想了解更好的定义动态矩阵的方法(仅限vector)!!!!
展开
 我来答
boyyandgirll
2015-11-21 · TA获得超过1.3万个赞
知道大有可为答主
回答量:2万
采纳率:95%
帮助的人:8289万
展开全部
D3DXMATRIX* WINAPI D3DXMatrixInit(D3DXMATRIX* pOut,

float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44)
{
pOut->_11 = m11; pOut->_12 = m12; pOut->_13 = m13; pOut->_14 = m14;
pOut->_21 = m21; pOut->_22 = m22; pOut->_23 = m23; pOut->_24 = m24;
pOut->_31 = m31; pOut->_32 = m32; pOut->_33 = m33; pOut->_34 = m34;
pOut->_41 = m41; pOut->_42 = m42; pOut->_43 = m43; pOut->_44 = m44;
return pOut;
}
D3DXMATRIX* WINAPI D3DXMatrixMultiply
( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 )
{
ATLASSERT(pOut!=NULL&&pM1!=NULL&&pM2!=NULL);
D3DXMATRIX matTemp;
float fSum = 0;
for (int nRow=0; nRow<4; nRow++)
{
for (int nCol=0; nCol<4; nCol++)
{
fSum=0;
for (int nIndex=0;nIndex<4; nIndex++)
{
fSum+=pM1->m[nRow][nIndex]*pM2->m[nIndex][nCol];
}
matTemp.m[nRow][nCol] = fSum;
}
}
pOut[0]=matTemp;
return pOut;
}
D3DXMATRIX* WINAPI D3DXMatrixScaling
( D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz )
{
D3DXMatrixIdentity(pOut);
pOut->_11=sx;
pOut->_22=sy;
pOut->_33=sz;
return pOut;
}
D3DXMATRIX* WINAPI D3DXMatrixTranslation
( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z )
{
D3DXMatrixIdentity(pOut);
pOut->_41=x;
pOut->_42=y;
pOut->_43=z;
return pOut;
}
D3DXMATRIX* WINAPI D3DXMatrixRotationX
( D3DXMATRIX *pOut, FLOAT Angle )
{
FLOAT fCos=cos(Angle);
FLOAT fSin=sin(Angle);
D3DXMatrixInit(pOut,1,0,0,0,
0,fCos,fSin,0,
0,-fSin,fCos,0,
0,0,0,1);
return pOut;
}
D3DXMATRIX* WINAPI D3DXMatrixRotationY
( D3DXMATRIX *pOut, FLOAT Angle )
{
FLOAT fCos=cos(Angle);
FLOAT fSin=sin(Angle);
D3DXMatrixInit(pOut,
fCos,0,-fSin,0,
0,1,0,0,
fSin,0,fCos,0,
0,0,0,1);
return pOut;
}
D3DXMATRIX* WINAPI D3DXMatrixRotationZ
( D3DXMATRIX *pOut, FLOAT Angle )
{
FLOAT fCos=cos(Angle);
FLOAT fSin=sin(Angle);
D3DXMatrixInit(pOut,
fCos,0,fSin,0,
-fSin,fCos,0,0,
0,0,1,0,
0,0,0,1);
return pOut;
}
D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll
( D3DXMATRIX *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll )
{
D3DXMATRIX matTemp;
D3DXMatrixRotationY(pOut,Yaw);
D3DXMatrixRotationX(&matTemp,Pitch);
D3DXMatrixMultiply(pOut,pOut,&matTemp);
D3DXMatrixRotationZ(&matTemp,Roll);
D3DXMatrixMultiply(pOut,pOut,&matTemp);
return pOut;
}
D3DXVECTOR4* WINAPI D3DXVec4Transform
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM )
{
FLOAT fSum = 0;
ATLASSERT(pOut!=pV);
for (int nCol=0; nCol < 4; nCol++)
{
fSum=0;
for (int nRow=0; nRow<4; nRow++)
{
fSum+=((FLOAT*)pV)[nRow]*pM->m[nRow][nCol];
}
((FLOAT*)pOut)[nCol] = fSum;
}
return pOut;
}
D3DXVECTOR4* WINAPI D3DXVec4TransformArray
( D3DXVECTOR4 *pOut, UINT OutStride,
CONST D3DXVECTOR4 *pV, UINT VStride,
CONST D3DXMATRIX *pM, UINT n )
{
ATLASSERT(pOut!=pV);
return pOut;
}

注意:
不要用中文状态下的标点符号,否则会有很多错误。
兔子和小强
推荐于2017-09-29 · TA获得超过6946个赞
知道大有可为答主
回答量:3332
采纳率:74%
帮助的人:1429万
展开全部
#include<iostream>
#include<vector>
using namespace std;
void inputM(vector<vector<int>> &T)
{
    int i, j, d, row, col;
    vector<int> R;
    cout << "Enter the row and column: ";
    cin >> row >> col;
    cout << "Enter the matrix:" << endl;
    for(i=0; i<row; ++i)
    {
        R.clear();
        for(j=0; j<col; ++j)
        {
            cin >> d;
            R.push_back(d);
        }
        T.push_back(R);
    }
}
void printM(vector<vector<int>> &T)
{
    int i, j, row = T.size(), col = T[0].size();
    for(i=0; i<row; ++i)
    {
        for(j=0; j<col; ++j)
            cout << T[i][j] << ' ';
        cout << endl;
    }
}
int main()
{
     /*typedef*/ vector<vector<int>> T;
     inputM(T);
     printM(T);
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式