附加输出文件名 [英] append output filename

查看:86
本文介绍了附加输出文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Borland C ++。


我运行一个生成输出数据文件的程序,比如''Voltage.dat'',

'' Current.dat'。我的代码中有一个变量(比如N),对于N的各种值(每个N值),我生成这些输出数据文件。

之后为给定的N值运行一次程序(比如N等于

1),当程序结束时,我手动追加生成的

文件名,其值为N,例如''Voltage_N1.dat'',

''Current_N1.dat''。然后我回到代码,使N = 2,重复

程序并将生成的输出文件附加''_N2''等等。


是否有一种自动附加文件名的简单方法?在

换句话说,我想在循环中运行程序以获得各种值

of N(我知道这一点,即如何制作循环:),以及每次运行,生成的

文件(例如''Voltage_N'')都附加N

的值,即1,2等等,然后是扩展名''.dat''。

我在阅读帮助文件后知道有类似

strcpy和strcat的功能,但是无法弄清楚如何使用它们和他们的

确切的格式。另外,我不熟悉C ++中的Classes指针。

(一个易于理解和基本的回复步骤将非常好

赞赏)。


谢谢

I am using Borland C++.

I run a program which generates output data files, say ''Voltage.dat'',
''Current.dat''. I have a variable in my code (say N), and for various
values of N (for each value of N), I generate these output data files.
After running the program once for a given value of N (say N equal to
1) and when the programme is finished, I manually append the generated
filename with the value of N, such as ''Voltage_N1.dat'',
''Current_N1.dat''. Then I go back to the code, make N=2, repeat the
procedure and append the generated output files with ''_N2'' etc.

Is there a simple way of appending the filenames automatically? In
other words, I want to run the programme in a loop for various values
of N (I know this bit i.e. how to make a loop:), and for each run, the
files generated (such as ''Voltage_N '') is appended by the value of N
i.e. 1, 2 and so on, followed by the extension ''.dat''.
I know after reading the help file that there are functions like
strcpy and strcat, but couldn''t figure out how to use them and their
exact format. Also, I am not conversant with Classes, pointers in C++.
(An easy to understand and basic reply with steps will be highly
appreciated).

Thankyou

推荐答案



vj写道:

vj wrote:

我正在使用Borland C ++。


我运行一个生成输出数据文件的程序,比如''Voltage.dat'',

''Current.dat''。我的代码中有一个变量(比如N),对于N的各种值(每个N值),我生成这些输出数据文件。

之后为给定的N值运行一次程序(比如N等于

1),当程序结束时,我手动追加生成的

文件名,其值为N,例如''Voltage_N1.dat'',

''Current_N1.dat''。然后我回到代码,使N = 2,重复

程序并将生成的输出文件附加''_N2''等等。


是否有一种自动附加文件名的简单方法?在

换句话说,我想在循环中运行程序以获得各种值

of N(我知道这一点,即如何制作循环:),以及每次运行,生成的

文件(例如''Voltage_N'')都附加N

的值,即1,2等等,然后是扩展名''.dat''。

我在阅读帮助文件后知道有类似

strcpy和strcat的功能,但是无法弄清楚如何使用它们和他们的

确切的格式。另外,我不熟悉C ++中的Classes指针。

(一个易于理解和基本的回复步骤将非常好

赞赏)。


谢谢
I am using Borland C++.

I run a program which generates output data files, say ''Voltage.dat'',
''Current.dat''. I have a variable in my code (say N), and for various
values of N (for each value of N), I generate these output data files.
After running the program once for a given value of N (say N equal to
1) and when the programme is finished, I manually append the generated
filename with the value of N, such as ''Voltage_N1.dat'',
''Current_N1.dat''. Then I go back to the code, make N=2, repeat the
procedure and append the generated output files with ''_N2'' etc.

Is there a simple way of appending the filenames automatically? In
other words, I want to run the programme in a loop for various values
of N (I know this bit i.e. how to make a loop:), and for each run, the
files generated (such as ''Voltage_N '') is appended by the value of N
i.e. 1, 2 and so on, followed by the extension ''.dat''.
I know after reading the help file that there are functions like
strcpy and strcat, but couldn''t figure out how to use them and their
exact format. Also, I am not conversant with Classes, pointers in C++.
(An easy to understand and basic reply with steps will be highly
appreciated).

Thankyou




vj写道:

vj wrote:

我正在使用Borland C ++。


我运行一个生成输出数据文件的程序,比如''Voltage.dat'',

' Current.dat。我的代码中有一个变量(比如N),对于N的各种值(每个N值),我生成这些输出数据文件。

之后为给定的N值运行一次程序(比如N等于

1),当程序结束时,我手动追加生成的

文件名,其值为N,例如''Voltage_N1.dat'',

''Current_N1.dat''。然后我回到代码,使N = 2,重复

程序并将生成的输出文件附加''_N2''等等。


是否有一种自动附加文件名的简单方法?在

换句话说,我想在循环中运行程序以获得各种值

of N(我知道这一点,即如何制作循环:),以及每次运行,生成的

文件(例如''Voltage_N'')都附加N

的值,即1,2等等,然后是扩展名''.dat''。

我在阅读帮助文件后知道有类似

strcpy和strcat的功能,但是无法弄清楚如何使用它们和他们的

确切的格式。另外,我不熟悉C ++中的Classes指针。

(一个易于理解和基本的回复步骤将非常好

赞赏)。


谢谢
I am using Borland C++.

I run a program which generates output data files, say ''Voltage.dat'',
''Current.dat''. I have a variable in my code (say N), and for various
values of N (for each value of N), I generate these output data files.
After running the program once for a given value of N (say N equal to
1) and when the programme is finished, I manually append the generated
filename with the value of N, such as ''Voltage_N1.dat'',
''Current_N1.dat''. Then I go back to the code, make N=2, repeat the
procedure and append the generated output files with ''_N2'' etc.

Is there a simple way of appending the filenames automatically? In
other words, I want to run the programme in a loop for various values
of N (I know this bit i.e. how to make a loop:), and for each run, the
files generated (such as ''Voltage_N '') is appended by the value of N
i.e. 1, 2 and so on, followed by the extension ''.dat''.
I know after reading the help file that there are functions like
strcpy and strcat, but couldn''t figure out how to use them and their
exact format. Also, I am not conversant with Classes, pointers in C++.
(An easy to understand and basic reply with steps will be highly
appreciated).

Thankyou





试试这个....


FILE fp1;

char filename [30];


for(int i = 0; i< 10; i ++ )

{

......

......


sprintf(filename," Voltage_N%d",i);

fp1 = fopen(filename," w");


//全部这里''写入文件''..


fclose(fp1);

}


我猜这个wud解决了你的问题...


5月24日上午10:05,vj< vijayjany ... @ gmail.comwrote:
Hi,

Try this....

FILE fp1;
char filename[30];

for(int i=0;i<10;i++)
{
......
......

sprintf(filename,"Voltage_N%d",i);
fp1 = fopen(filename,"w");

//Do all the ''Writing to the File'' here..

fclose(fp1);
}

I guess this wud solve ur problem...

On May 24, 10:05 am, vj <vijayjany...@gmail.comwrote:

我正在使用Borland C ++。


我运行一个生成输出数据文件的程序,比如''Voltage.dat'',

''Current.dat''。我的代码中有一个变量(比如N),对于N的各种值(每个N值),我生成这些输出数据文件。

之后为给定的N值运行一次程序(比如N等于

1),当程序结束时,我手动追加生成的

文件名,其值为N,例如''Voltage_N1.dat'',

''Current_N1.dat''。然后我回到代码,使N = 2,重复

程序并将生成的输出文件附加''_N2''等等。


是否有一种自动附加文件名的简单方法?在

换句话说,我想在循环中运行程序以获得各种值

of N(我知道这一点,即如何制作循环:),以及每次运行,生成的

文件(例如''Voltage_N'')都附加N

的值,即1,2等等,然后是扩展名''.dat''。

我在阅读帮助文件后知道有类似

strcpy和strcat的功能,但是无法弄清楚如何使用它们和他们的

确切的格式。另外,我不熟悉C ++中的Classes指针。

(一个易于理解和基本的回复步骤将非常好

赞赏)。


谢谢
I am using Borland C++.

I run a program which generates output data files, say ''Voltage.dat'',
''Current.dat''. I have a variable in my code (say N), and for various
values of N (for each value of N), I generate these output data files.
After running the program once for a given value of N (say N equal to
1) and when the programme is finished, I manually append the generated
filename with the value of N, such as ''Voltage_N1.dat'',
''Current_N1.dat''. Then I go back to the code, make N=2, repeat the
procedure and append the generated output files with ''_N2'' etc.

Is there a simple way of appending the filenames automatically? In
other words, I want to run the programme in a loop for various values
of N (I know this bit i.e. how to make a loop:), and for each run, the
files generated (such as ''Voltage_N '') is appended by the value of N
i.e. 1, 2 and so on, followed by the extension ''.dat''.
I know after reading the help file that there are functions like
strcpy and strcat, but couldn''t figure out how to use them and their
exact format. Also, I am not conversant with Classes, pointers in C++.
(An easy to understand and basic reply with steps will be highly
appreciated).

Thankyou



这篇关于附加输出文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆