1
    template< typename T >
    T Read( const char* Section, const char* Key )
    {
        SecureZeroMemory( m_Result, sizeof( m_Result ) );
        GetPrivateProfileString( Section, Key, 0, m_Result, sizeof( m_Result ), m_File.FullPath );
        std::istringstream Cast( m_Result );
        T Result{ };
        Cast >> std::noskipws >> Result;
        return Result;
    }

m_Result is a member variable of my class. ( char[256] ).

Objective: Try to return all types that i insert on template arg.

Issue: When i send std::string with: "Example Text Return" it returns me "Example" instead of "Example Text Return".

Where is the error? I tried a lot of skipws or noskipws or ws...

Sorry for the english, i'm a brazilian guy.

1 Answers1

1

std::noskipws only reads any initial whitespace. The >> operator overload for a std::string always stops reading the string at the first encountered whitespace character. std::noskipws makes it read the initial whitespace, but the conversion still stops at the first whitespace character following the first non-whitespace character.

What you need to do is to specialize this template function for a std::string, and just return the m_Result without any conversion.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • Ok, but i wanna to use that function like this: int Key = Read( "Section", "Key" ); Thats why i used a template function. But if dont have another solution, i'll overload for const char*. – Cainan Kenji Kita Nov 28 '15 at 02:00
  • There's nothing in my answer that is contrary to what you intend to do. Your template function remains unchanged, all that's needed is an explicit specialization for a std::string. And not for a const char *, by the way. – Sam Varshavchik Nov 28 '15 at 02:15
  • Thank you, i found a solution. I cant vote ur answer :( sorry hehe. – Cainan Kenji Kita Nov 28 '15 at 02:57