C++ 程序大虾请进

来源:百度知道 编辑:UC知道 时间:2024/06/20 16:41:04
#include<fstream.h>
#include<string.h>

class FileIO
{
public:
void makefile(char str[]);
};
void FileIO::makefile(char str[])
{
char string[200]={"20020108#存入#2000.00#3090.00&20020108#支取#-2.00#190.00"};
int strl=strlen(string);
char substring[strl];
ofstream outf("C:\file.txt");
if(!outf)
{
cout<<"Cannot open file \n";
}
for(int i=0; i<=strl-1; i++)
for(int j=0; j<=strl-1; j++)
{
if(str[i]!="#")
{
substring[j]=str[i];
outf.put(substring);
}
else
{
outf.put("\n");
}
{
}
}

void main()
{
FileIO fi;
fi.makefile(char string);
}
}

请指点此程序的问题,请教如何修改能够通过编译
程序目的是:将外面传进的字符串以#号为分隔行写
入一个文本文件。本人是初学者,先谢了!
请问生成的文件中为什么

/////////我帮你改了,编译通过,你试试看
///////////////////////
#include<fstream.h>
#include<string.h>

class FileIO
{
public:
void makefile(char str[]);
};
void FileIO::makefile(char str[])
{

//int strl=strlen(str);
char *psubstring=str; //
ofstream outf("C://file.txt");
if(!outf)
{
cout<<"Cannot open file \n";
}
//for(int i=0; i<=strl-1; i++)
//for(int j=0; j<=strl-1; j++)
while(*psubstring!=NULL)
{
// if(str[i]!='#')
if(*psubstring!='#')
{
//*psubstring=str[i];
outf.put(*psubstring);

}
else
outf.put('\n');
psubstring++;

}
}

void main()
{

char string[200]={"20020108#存入#2000.00#3090.00&20020108#支取#-2.00#190.00"};