求C++代码(急)!

来源:百度知道 编辑:UC知道 时间:2024/06/17 16:33:28
a. Create a program which:
i. Opens a file, given a file name from the user.
ii. Receives a line of input from the user, then outputs that line to the given file.
This will continue until the line input by the user is “-1” which indicates, the
end of input.
iii. Defines 2 functions which:
1. Opens the file
2. Writes to the file
The outline is given below.
// include appropriate header files
// constant declarations
// function prototypes
int main ()
{
// declare file stream variable
// call function to open file
// call function to write to file
// close file
return 0;
}
b. Modify the program so that the rather than overwriting the given file, the input is
appended to the end. Run it to ensure that it works before continuing.

7.读取文件
char sRead[1024];
CFile mFile(_T(%%1),CFile::modeRead);
while (sRead!=null)
{
mFile.Read(sRead,1024);
CString %%2=CString(sRead);
%%3
}

8.写入文件
CFile mFile(_T(%%1), CFile::modeWrite|CFile::modeCreate);
mFile.Write(%%2,sizeof(%%2));
mFile.Flush();
mFile.Close();

9.写入随机文件
char szTempPath[_MAX_PATH],szTempfile[_MAX_PATH];
GetTempPath(_MAX_PATH, szTempPath);
GetTempFileName(szTempPath,_T ("my_"),0,szTempfile);
CFile m_tempFile(szTempfile,CFile:: modeCreate|CFile:: modeWrite);
char m_char='a';
m_tempFile.Write(&m_char,2);
m_tempFile.Close();
//循环写入多个值
strTempA;
int i;
int nCount=6;
//共有6个文件名需要保存
for (i=0;i{strTemp.Format("%d",i);
strTempA=文件名;
//文件名可以从数组,列表框等处取得.
::WritePrivateProfileString("UseFileName","FileName"+strTemp,strTempA,
c:\\usefile\\usef