Share via


How to add text file to a project (not inside of resource) (C++)

Question

Monday, February 10, 2014 1:30 PM

I'd like to add file (txt) to project

I'd like to have it not in resource, but inside of folder of my built project.

Like in g++. I'd like to add it and use it like this:

+MY FOLDER
|-main.cpp
|-file.txt

I'd like to compile it and open it in c++ by name like this:

ifstream fin;
fin.open("file.txt");
//...

How to do this?

All replies (1)

Monday, February 10, 2014 4:38 PM âś…Answered

In the 'Solution Explorer' right click your 'project' (NOT the 'Solution' node at the top) and select Add > New Item.

In the 'Add New Item' dialog, select "Text File" and give it a name (file.txt).

Now, for your new txt file to be included in your compiled output, you need to tell Visual Studio how to handle the file during compile time.

To do this, select your text file in the 'Solution Explorer' and look at the properties panel.  There is a property called, "Copy to Output Directory," and change the value to "Copy if newer".  You may also want to confirm that the property "Build Action" is set to "Content" and not "Resource."

I hope that solves your problem. Have a great day!

ZdPav