c++ - How to create and write a file into a folder on the same directory?
问题描述
I've been creating and writing into a file in the directory I have all my project files, but now that i finished everything, I'm trying to tidy things up.
My executable is creating and writing into a file in the same directory that it's placed on. Now, I've created a folder in this same directory called 'models' and i need the previous mentioned file to be created in this folder. I have a Windows machine and i'm using C++.
What i have at the moment, in a simplified way is:
void createFile(string fich){
ofstream file(fich);
}
I've tried things like
void createFile(string fich){
string path = "../models/" + fich;
ofstream file(path);
}
without any success. How could i solve this?
解决方案
推荐阅读
- elixir - 使用 Phoenix 从 ARC 上传读取二进制数据 -- db 仅显示文件名
- laravel - 所有值都没有插入我的数据库(laravel-5.7)
- sql-server - 多个 SELECTS 进入单个结果行
- python - 为输赢造成延迟
- xilinx - 当被调用函数不可合成时合成调用函数
- php - 在循环中将三个元素增加一个数字
- google-apps-script - Google Scripts - 多重保护的 removeEditors()
- reference - IBM Integration Bus ESQL 对 OutputRoot 的引用不起作用
- c# - C# 和 WPF,当使用 mvvm 样式和按钮操作作为带有命令参数的命令时,如何始终在命令参数中创建新对象?
- angular - 在 angular6 中传递 JSON.stringfy 中的多个值