.cppファイル内に作成された.txtファイルにコンテンツを書き込むために.cppプログラムを作成しました。
なんとか目的のコンテンツを書き込めましたが、作成したファイルを端末から開こうとすると、そこにあるのに見つからないと表示されます。
で開こうとしvi
たりnano
、内容が空だったりします。これは、新しいファイルを作成するようなものです。
しかし、ターミナルの外で開くと、思い通りの内容が見えます。
何が問題になる可能性があり、どうすればこの状況を修正できますか?
以下、コードを追加しました。
問題はsystem(buffer)
コマンドにあります。次のエラーが表示されますsh: cannot open video2.txt: No such file
。コマンドプロンプトからファイルを開こうとしましたが、上記の状況になります。
int main(int argc,char* argv[])
{
fstream RawStipFile;
RawStipFile.open(strcat(argv[1],".txt"));
string line;
if (RawStipFile.is_open())
{
getline(RawStipFile, line);
int i = 0;
ofstream OutVideoStip;
ofstream VideoList;
VideoList.open("VideoList.txt");
while ( RawStipFile.good() )
{
getline (RawStipFile,line);
char* l;
l = (char*) malloc(sizeof(char));
l[0]=line[0];
//cout<<line[0]<<endl;
if (line[0]==35)
{
if (OutVideoStip.is_open())
{
OutVideoStip.close();
}
i++;
//char* base;
//base = (char*) malloc(1000*sizeof(char));
//sprintf(base, "%d", i);
char* b;
b = &line[1];
VideoList<<b<<endl;
OutVideoStip.open(strcat(b, ".txt"));
}
else
{
OutVideoStip << line << endl;
}
}
OutVideoStip.close();
RawStipFile.close();
VideoList.close();
}
else
{
cout << "Unable to open file \n";
}
fstream VideoNames;
VideoNames.open("VideoList.txt", fstream::in);
if (VideoNames.is_open())
{
while ( VideoNames.good() )
{
getline(VideoNames, line);
line=line.substr(1,line.length());
if (line.compare(""))
{
string initial = "./txt2mat<";
initial.append(line);
initial.append(".txt>");
initial.append(line);
initial.append(".dat");
cout<<initial<<endl;
const char* buffer;
buffer = initial.c_str();
system(buffer);
}
}
}
else
{
cout<<"Unable to open file. \n";
}
VideoNames.close();
return 0;
}