Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 读取文件中写入的目录位置,并在c+中的该目录中创建新文件+;_C++_Debugging_File Io_Runtime Error_Codeblocks - Fatal编程技术网

C++ 读取文件中写入的目录位置,并在c+中的该目录中创建新文件+;

C++ 读取文件中写入的目录位置,并在c+中的该目录中创建新文件+;,c++,debugging,file-io,runtime-error,codeblocks,C++,Debugging,File Io,Runtime Error,Codeblocks,下面是创建目录的代码,它是switch case,所以我把它放在了一个块中 { int index = 0 ; char path[60]; system ( " cls " ) ; ofstream ofile ; cout < < " \ n Enter path to store bills < <( ! Without spaces after symbols like slashes and colons < <

下面是创建目录的代码,它是switch case,所以我把它放在了一个块中

{
int  index = 0 ;

char  path[60];

system ( " cls " ) ;

ofstream  ofile ;

cout < < " \ n Enter path  to  store  bills 

< <( ! Without  spaces  after  symbols  like  slashes  and  colons

< <e.g.  \" c : \\ billing  folder \\ \" : ";

fflush ( stdin ) ;

cin.getline ( path , 60 ) ;

mkdir ( path ) ;

ofile.open ( " Path.dat " , ios :: trunc | ios :: out | ios :: binary ) ;

ofile.write ( path , strlen ( path ) );

ofile.close ( ) ;

goto here1 ;

}
{
int指数=0;
字符路径[60];
系统(“cls”);
气流;
cout<<“\n输入存储账单的路径
这是错误的

char *newPath = new char[index];
你应该

char *newPath = new char[index + foldName.size() + 1];
因为对于C风格的字符串,您总是需要分配足够的内存来容纳所有字符

因为这是困难的,你应该总是使用C++字符串。

std::string newPath = path;
newPath += foldName;

它正确、简短、易于编写且易于理解。

处理该文件的任何函数都没有错误检查。如果添加错误检查,则可能会发现错误,
std::string newPath = path;
newPath += foldName;