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 8148885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:44:03+00:00 2026-06-06T14:44:03+00:00

hope someone can answer this. Here is some sample code. namespace std { #ifdef

  • 0

hope someone can answer this. Here is some sample code.

namespace std {
#ifdef UNICODE
typedef wstring tstring;
typedef wstringstream tstringstream;
#define tcout std::wcout
#else
typedef string tstring;
typedef stringstream tstringstream;
#define tcout std::cout
#endif
typedef regex_iterator<std::tstring::const_iterator> TRegexIterator;
}

std::TRegexIterator::regex_type nPattern(_TEXT("-?[0-9]+(\\.[0-9]+)?((e|E)(\\+|-)[0-9]+)?"));
std::match_results<std::tstring::const_iterator> theMatches;
std::tstring test(_TEXT("-1.323E-23"));

tcout << _TEXT("Lvalue target string") << std::endl;
if (std::regex_match(test, theMatches, nPattern))
{
    for (auto i= 0; i < theMatches.size(); ++i)
        tcout << theMatches[i] << std::endl;
}

tcout << _TEXT("Rvalue target string") << std::endl;
if (std::regex_match(std::tstring(_TEXT("-1.323E-23")), theMatches, nPattern))
{
    for (auto i= 0; i < theMatches.size(); ++i)
        tcout << theMatches[i] << std::endl;
}

Ok so the problem I’m getting is that the first match result with an rvalue target string is
” 1.323E-23″ (yes, with a starting space) instead of the expected “-1.323E-23”. I’m thinking it’s because “std::match_results” stores pointers instead of data, but in that case why is the first parameter to “std::regex_match” a “const std::string&”? (this I verified from Intellisense). An “std::string&” appears more appropriate.
I’m using the VS11 beta C++ compiler.

  • 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-06-06T14:44:04+00:00Added an answer on June 6, 2026 at 2:44 pm

    Yes,

    it’s because “std::match_results” stores pointers instead of data.

    for example, test below code:

    tcout << _TEXT("Lvalue target string") << std::endl;
    if (std::regex_match(test, theMatches, nPattern))
    {
        test = _TEXT(""); // change 'test' to invalidate 'theMatches' pointers
        for (auto i= 0; i < theMatches.size(); ++i)
            tcout << theMatches[i] << std::endl; // MEMORY ERROR!!!
    }
    

    But, Why you believe

    An “std::string&” appears more appropriate than “const std::string&”.

    In my opinion “const std::string&” appears more appropriate, because ‘std::regex_match’ don’t need to change this parameter.

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

Sidebar

Related Questions

I hope someone can help me here. I'm having trouble loading this variable. Right
I've searched far and wide and I hope someone can answer this question. I'm
I hope someone can answer this question, its been bugging me for a while
Hope someone can help i cant seem to get my head around this, i
Hope someone can help me out with this problem I am having. I just
I hope someone can help me with this, as I'm unable to find the
I hope someone can help here, we're having an incredibly annoying time with Visual
Hope someone can help with this. I've been up and down the web and
I've almost got the answer here, but I'm missing something and I hope someone
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID

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.