首页 > 编程语言 > 详细

C++常用速查

时间:2019-12-23 23:37:54      阅读:88      评论:0      收藏:0      [点我收藏+]
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;
}

C++常用速查

原文:https://www.cnblogs.com/yaos/p/12088053.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!