Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6697245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:26:18+00:00 2026-05-26T06:26:18+00:00

The solution is probably obvious, but I do not see it. I have this

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:26:18+00:00Added an answer on May 26, 2026 at 6:26 am

    As I found out the two NULL characters stored at the end of the string were the problem. Apparently std::wstring does not care about NULLs like good old C string does. If it thinks a string is 10 characters long, it does not care if some of those 10 characters are NULL characters. If you then append to that string, the additional characters get appended after the 10ths char. If the last characters of the string happen to be NULLs, you get:

    C:\\SomePath\0\0\\*.*

    Such a string cannot really be used anywhere.

    How did I get the NULL characters at the end of the original string? I used wstring.resize() in some other function which pads the string with NULLs. I did this in order to pass &string[0] to a Windows API function expecting a LPWSTR.

    Now that I know this does not work I use a true LPWSTR instead. That is a bit more clumsy, but it works. Coming from MFC, I thought I could use std::wstring like CString with its GetBuffer and Release methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably a long question for a simple solution, but here goes... I have a
This is probably easy but I am getting stuck: when I build a solution
This is probably a simple question but I can't seem to find the solution.
This probably an obvious solution, but I've been hitting a wall for a while
This is probably a no brainer but... I've just opened a solution in VS2008
This is probably the most classic database problem. I have an E-commerce software solution
I'm new with Objective-C, so there probably is a simple solution to this. I
I'm probably missing something really obvious but I have an xml file that I
I'm using .Net 2.0 and this is driving me crazy but there's probably some
I see it in the solution I am looking for, but if I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.