Hello,

I've added TXT file to my resource, but now I need to know how to access data in it?

can I use iostream to read data?

I have this:

resource.rc

LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDR_0_1            0              "..\\..\\..\\..\\..\\Desktop\\test.txt"

resource.h

#define IDR_0_1                                 119

main.cpp

HRSRC hRes = FindResource(0, MAKEINTRESOURCE(IDR_0_1), "0");
HGLOBAL hData = LoadResource(0, hRes);
LPVOID data = LockResource(hData);

Recommended Answers

All 9 Replies

Member Avatar for MonsieurPointer

The line

IDR_0_1            0              "..\\..\\..\\..\\..\\Desktop\\test.txt"

tells me that you have a resource table and that it contains one string entry (IDR_0_1), whose value is ..\\..\\..\\..\\..\\Desktop\\test.txt. It doesn't seem like the actual text file test.txt has been added as a resource. Or am I wrong?

ya, u are wrong, I've added user resource with ResEdit, that "..\\..\\..\\..\\..\\Desktop\\test.txt" is the path to the file

Member Avatar for MonsieurPointer

Alrighty then. In that case, you will need to first access the file itself by reading its path from the resource table. You should be able to then read in the file with iostream.

can u give me some example of writing to that file?

I just noticed an mistake in my post, it should me "fstream" instead of "iostream", sorry :P

Member Avatar for MonsieurPointer

Which IDE are you using? Visual Studio?
In VS I don't have the option to add a file as a resource.

bump?

commented: Do not bump threads. It's rude. -4

bump?

Do not be rude and bump threads. If someone can help they will when they get to it.
And this bump is exceptionally rude because you were asked questions and rather than answer them you just said bump? I know I would refuse to help with that attitude.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.