首页 > 解决方案 > 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?

标签: c++

解决方案


推荐阅读