The solution is probably obvious, but I do not see it. I have this simple C++ code:
// Build the search pattern
// sPath is passed in as a parameter into this function
trim_right_if(sPath, is_any_of(L"\\"));
wstring sSearchPattern = sPath + L"\\*.*";
My problem is that the + operator has no effect (checked in debugger). The string sSearchPattern
is initialized to the value of sPath
only.
Notes: sPath
is a wstring
.
Example of what I want to achieve:
sSearchPattern -> C:\SomePath\*.*
More Info:
When I look at sPath in the debugger, I see two NULL characters after the last character. When I look at sSearchPattern, the "\*.*" is appended, but after the two NULL characters. Any explanation for that?
This should work, and indeed works for me on VS2010, SP1:
#include <iostream>
#include <string>
int main()
{
const std::wstring sPath = L"C:\\SomePath";
const std::wstring sSearchPattern = sPath + L"\\*.*";
std::wcout << sSearchPattern << L'\n';
return 0;
}
This prints
C:\SomePath\*.*
for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With