std::stringstream 不读取空格

std::stringstream not reading whitespace

    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是我的class的一个成员变量。 ( 字符[256] ).

Objective:尝试 return 我在模板 arg 上插入的所有类型。

问题:当我用 "Example Text Return" 发送 std::string 时,它 return 是我 "Example" 而不是 "Example Text Return".

哪里出错了?我尝试了很多 skipws 或 noskipws 或 ws...

对不起英语,我是巴西人。

std::noskipws 只读取任何初始空格。 std::string>> 运算符重载总是在遇到第一个空白字符时停止读取字符串。 std::noskipws 使其读取初始空白,但转换仍停止在第一个非空白字符后的第一个空白字符处。

您需要做的是将此模板函数特化为 std::string,并且只是 return 和 m_Result,无需任何转换。