0

I want a text file to be included in the build, so I used Add->Existing Item to load it into the solution. However, I can't open it in a ifstream unless I use an absolute path to the original file. I set Excluded from Build to No and Item Type to Text. For a relative path to file.txt, I tried "file.txt", "../file.txt", "/file.txt" but none of them work. I don't know if it's my syntax that's wrong, or if it's just not included in the build, or both.

The program is in C++.

I came across some old answers that mentioned an option to specify additional directories in the build, but I don't see it in Visual Studio 2013.

user2455117
  • 153
  • 2
  • 10
  • Confused. Why are you trying to compile a text file? Just what exactly are you trying to accomplish? – rrirower Mar 28 '14 at 18:22
  • I have a function that loads a user-specified text file through a filestream. I'd like to execute that function on a private "default" text file at runtime. – user2455117 Mar 28 '14 at 18:36
  • So you want to be able to read the file, but, not allow it to be seen by the user? What do you mean by "user-specified"? Will the file change often? – rrirower Mar 28 '14 at 18:38
  • Yes to the first question. That is precisely the goal. Perhaps I'm not going about it correctly. I mean it calls a openFileDialog, so the user can specify their own text file. It will vary from user to user. – user2455117 Mar 28 '14 at 18:41
  • If they can specify their own text file, how can you expect to protect the file from viewing? I have a solution if you have one specific file you want to protect, but, not for this scenario. – rrirower Mar 28 '14 at 18:44
  • I'll try to clarify: I want my _input_ text file to be kept private, not the _output_ from passing it to the function. It just happens to be used in the same function that allows the user to use their own text file. (The function parses a large quantity of data.) – user2455117 Mar 28 '14 at 18:52
  • Got it. Have you looked into creating a custom resource template from the text file? Effectively, you can bind the file to the executable, extract it at run time, read it, and remove it when done. – rrirower Mar 28 '14 at 18:58
  • You mean like resx or restext? I'm not familiar with how to read them. Is there an analogy to getline where you can specify a delimiter? Could you explain briefly/point me toward a reference? Thanks. – user2455117 Mar 28 '14 at 19:17
  • Per request in comment section, this has been discussed [here](http://stackoverflow.com/questions/2933295/embed-text-file-in-a-resource-in-a-native-windows-application) – rrirower Mar 28 '14 at 19:19

0 Answers0