我的stringstream没有读取输入

时间:2013-08-08 23:01:31

标签: c++ string templates stringstream

A类包含一个模板函数,它通过首先将对象传递给字符串流然后将该流转换为字符串来将对象读入字符串。

对于我的生活,我不知道为什么这些对象不会传递给流。可能是什么问题呢?我可以尝试解决这个问题吗?

class A
{
public:

    template<class T>
    void Input(const T&);

private:
    std::string result;
};

template<class T>
void A::Input(const T& obj)
{
    //Pass object to the stream
    std::ostringstream ss;
    ss << obj;

    //After this line, result == "" with size 1 (??), no matter the input
    result = ss.str();

    int test = 1234;
    ss << test;

    //Even with a test int, result == "" with size 1 (???)
    result = ss.str();
}

编辑:我正在使用Visual Studio Pro 2012。

0 个答案:

没有答案