小编swa*_*999的帖子

使用float或double或int的C/C++函数

我有单独的函数从文本文件中读取(取决于它是int,float还是double).我想只有一个带有附加参数的函数(不使用后续的IF语句).有人有想法吗?

以下是我当前功能的形式.

float * read_column_f (char * file, int size_of_col){
...
col = (float*) malloc (height_row * sizeof(float));
...  return(col);}


double *    read_column_d (char * file, int size_of_col){
...
col = (double*) malloc (height_row * sizeof(double));
...  return(col);}


int *   read_column_i (char * file, int size_of_col){
...
col = (int*) malloc (height_row * sizeof(int));
...  return(col);}
Run Code Online (Sandbox Code Playgroud)

编辑:我想用C++实现它,使用的C风格语法是由于内存偏好.

c c++ io text

5
推荐指数
2
解决办法
6315
查看次数

标签 统计

c ×1

c++ ×1

io ×1

text ×1