C++常用速查

int main()
{
    int arr[2][5] =
    {
        {1,8,12,20,25},
        {5,9,13,24,26}
    };
}
void f(double p[][10]) {
}
#include <Eigen/Dense>
#include <iostream>
using namespace std;
int main()
{
  Eigen::MatrixXf m(3,3);
  m << 1,2,3,
       4,5,6,
       7,8,9;
  cout << "Here is the matrix m:" << endl << m << endl;
  cout << "2nd Row: " << m.row(1) << endl;
  m.col(2) += 3 * m.col(0);
  cout << "After adding 3 times the first column into the third column, the matrix m is:\n";
  cout << m << endl;
Matrix3f m;
m << 1, 2, 3,
     4, 5, 6,
     7, 8, 9;
std::cout << m;
MatrxXd M = MatrixXd::Zero(50,50);
//矩阵转数组
double* test = M.data();
//数组转矩阵
Map<MatrixXd>tM(test, 50, 50);
MatrixXd M = MatrixXd::Zero(5, 5);
ofstream fout("test.txt");
fout << M;
fout.close();
#include<iostream>
int main()
{
    int a[4] = {0,1,2,3};
    int b[4];
    std::copy(a, a+4, b);
    b[3] = 5;
    std::cout << "a3 =" << a[3] << std::endl << "b3 =" << b[3] << std::endl;

    int c[4] = {0,1,2,3};
    int *d = c;
    d[3] = 5;
    std::cout << "c3 =" << c[3] << std::endl << "d3 =" << d[3] << std::endl;
    return 0;
}
double x[] = { .0, .1, .2, .3, .4 };
// Iterate through all elements
for (auto d : x)
{
    std::cout << d << std::endl;
}
int main()
{
	int sz = 5;
	sz = sz + 1;
	int a[5] = {1, 2, 3, 4, 5};
	int *b = new int[sz];
	for(int i=0; i<sz; i++)
	{
		b[i] = i;
		std::cout << b[i] << std::endl;
	}
	return 0;
}
posted @ 2019-12-23 21:43  2021年的顺遂平安君  阅读(277)  评论(0编辑  收藏  举报