Just started learning c++ and ive got a bit stuck :L
Im making a console application that injects a file into a process.
The file name and process name are both specified at the start of the code using

    char FileToInject[] = "File_Name.xxx";
    char ProcessName[] = "Process_Name.exe";

The console works fine, however the process name and file name are now fixed once ive compiled the console, and I am unable to change the file/process later on.

What I would like to do is have the console ask for file name, and the process name, so I dont need to create multiple console applications for different files and processes. Once the user has typed the file name and process name, I would like it to replace whats in the chars, so it is compatable with the rest of the code. Any suggestions?

Sorry if im aking too much, or maybe even a stupidly easy question, and please go easy on me. :)

Recommended Answers

All 2 Replies

What Moschops said, for C++, but you CAN use a C construct, const char* for the variables, and then assign a new string to them. Example:

const char* FileToInject = "File_Name.xxx";
const char* ProcessName = "Process_Name.exe";

// Do stuff with file and process names, and now change them.
FileToInject = "Another_File_Name.xxx"
ProcessName = "Another_Process_Name.exe"

// Do stuff with new file and process names.

The advantage of std::string class instances for these things is that they are much more dynamic and can deal with auto deleting the internal data when the string goes out of scope. Of course as long as your const char* items are string literals as the example shows, you don't have to worry about that.

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.