HI,
I started to play with files in C++ and I have a little problem.
Here is my c++ project and the problem:
main.cpp

#include <iostream>
#include "resource.h"
#include <windows.h>
#include <stdio.h>
#include <fstream>

using namespace std;

int main()
{
    HRSRC hRsrc;
    hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_MYTEXTFILE), TEXTFILE);
    if (hRsrc == NULL) {
        printf("Not found\n");
    } else {
        printf("Found\n");
    }
    //system("notepad " + myfile);
    return 0;
}

resource.h:

#ifndef RESOURCE_H_INCLUDED
#define RESOURCE_H_INCLUDED
#define TEXTFILE 0
#define IDR_MYTEXTFILE 0

#endif // RESOURCE_H_INCLUDED

Resource.rc:

#include "resource.h"

IDR_MYTEXTFILE TEXTFILE "Demo.txt"

Now it's time to explain my problem:
I want to run Demo.txt with Nodepad using "system("notepad " + myfile_Demo.txt);"
I don't know where is Demo.txt from Resources and How can I open it.
I use Code::Blocks - Download the c++ files from end of message.
I appreciate any suggestions.
Best regards,
Diana

Use Visual Studio C++ Express 2010. It's better

DL: Visaul Studio Express

#include <iostream>
#include <string>
#include <windows.h>
// using namespace std; // if u find the std:: namespace operator annoying each time

HINSTANCE g_hInstance;

int main( int argc, TCHAR **argv[], ... )
{
	std::string setPath = "C:\\Users\\YourUserNameHere\\Desktop\\Demo.txt";

	printf( "Looking for %s\n", setPath.data()/*c_str()*/ );
	Sleep( 1000 );

	while(( g_hInstance = ShellExecuteA( 0, "open", setPath.data(), 0, 0, SW_SHOW )) == 0 )
		Sleep( 100 );

	printf( "File has been found" );

	if( std::cin.get() )
		return EXIT_SUCCESS;
}

The

std::string setPath = "C:\\Users\\YourUserNameHere\\Desktop\\Demo.txt";

doesnt need to be opened from Desktop you can also just open it like this if you save your .txt file where the binary is:

std::string setPath = "Demo.txt" /*ShellExecuteA( 0, "open", "Demo.txt", 0, 0, SW_SHOW )*/
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.