小编use*_*891的帖子

我如何从文件中读取第一行?

ifstream infile;

string read_file_name("test.txt");

infile.open(read_file_name);

string sLine;

    while (!infile.eof())
    {
        getline(infile, sLine);         
        cout << sLine.data() << endl;
    }

    infile.close();
Run Code Online (Sandbox Code Playgroud)

该程序打印文件中的所有行,但我想只打印第一行.

c++

8
推荐指数
1
解决办法
4万
查看次数

如何在c ++中计算log base 2?

这是我的代码.

#include <iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include <cmath>
#include <functional>
using namespace std;
void main()
{
    cout<<log2(3.0)<<endl;

}
Run Code Online (Sandbox Code Playgroud)

但上面的代码给出了错误.错误代码是:错误C3861:'log2':找不到标识符.如何使用c ++计算log2?

c++

4
推荐指数
2
解决办法
2万
查看次数

如何使用特征库计算曼哈顿距离?

我有两个向量

int main(int argc, char *argv())
{
.........
Vector3f center(0.4,0.1,0.3) ;
Vector3f point(0.1,0.2,0.7);
.......
}
Run Code Online (Sandbox Code Playgroud)

如何使用特征库计算曼哈顿距离?我正在使用VS2010.

c++ eigen

3
推荐指数
2
解决办法
2560
查看次数

如何使用c ++计算回忆和精度?

有没有像Boost,Eigen,OpenCV这样可以计算回忆和精度的c ++库?

c++ boost opencv eigen

2
推荐指数
1
解决办法
1709
查看次数

如何计算文本文件中的所有数字?

我有一个文本文件,如下面的read.txt:

1.0 2.0 3.0 4.0
2.0 3.0 4.0 6
5.0 7 1.0 5.0
Run Code Online (Sandbox Code Playgroud)

calc.cpp:

void main()
{
    FILE *fp;
    fp=fopen("read.txt","r");
    double *read_feature = new double*[3];

    for(i = 0; i<3; i++) 
        read_feature[i] = new double[3];

    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            fscanf(fp,"%lf",&read_feature[i][j]);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想计算我的文本文件中的所有数字(read.txt).读取文本文件由浮点数和整数组成.上述文件的答案是12.

如何动态地使用c ++计算文件中的浮点数?这意味着不给出i和j的值.我需要程序会自动计算i和j的总数.

c c++

-5
推荐指数
1
解决办法
9749
查看次数

标签 统计

c++ ×5

eigen ×2

boost ×1

c ×1

opencv ×1