Task: A text input as command-line argument is to be written to a file.
Issue: Some encoding conversion is happening somewhere, so the file doesn't contain the exact text which was input. e.g. s%3A_blabla
becomes s:_blabla
. (Some HTML kind of thing)
Environment: Visual Studio 2019, C++17
How is the command-line argument being supplied: Using Smart Command Line Arguments extension. Also read 'Edit 1'.
How is the input being processed:
I've tried two methods:
static std::vector<const char*> args;
for (size_t i = 0; i < __argc; i++)
{
args.push_back(__argv[i]);
};
..........
std::string filePath = "random.txt";
std::string final_write(args[i+1]); //some value of i is chosen using a for loop
std::cout<<final_write<<std::endl;//this will print "s:_blabla"
std::ofstream out(filePath);
out << final_write;
Second method:
#include <atlstr.h>
........
LPWSTR *szArgList;
int argCount;
szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount);
for (int i = 0; i < argCount; i++)
{
CString pathCString(szArgList[i]);
std::cout<<pathCString<<std::endl; //Here also it prints "s:_blabla" for appropriate i
}
What I know:
- I don't think cout is at fault, because in first case the file writing also give the same transformed output, and if I explicitly modify the string and add "%3A" to it, the cout is able to display that normally. I've not tried writing to file in the second case, as cout tells that something fishy has already happened during input. It might be the extension, or an encoding issue somewhere else, I'm not sure. Any help?
Edit 1: As suggested, I checked the behaviour after removing the command line extension. I took input from Properties->Debugging section->Command Arguments, and I still face the same issue. Disabled the extension too.