我正在编译以下代码并得到以下错误。如何解决这个问题?谢谢你的帮助。


  错误C2079:“ issline”使用未定义的类
  'std :: basic_istringstream '1>与1>
  [1> _Elem = char,1>
  _Traits = std :: char_traits,1> _Alloc = std :: allocator 1>] 1> d:\ technical \ c ++ study \ readparsing \ readparsing \ main.cpp(49):错误
  C2440:'正在初始化':无法从'std :: string'转换为'int'1>
  没有可用的用户定义的转换运算符可以执行此操作
  转换,否则无法调用运算符
  1> d:\ technical \ c ++ study \ readparsing \ readparsing \ main.cpp(51):错误
  C2678:二进制'>>':找不到采用左操作数的运算符
  类型为“ int”(或没有可接受的转换)1>
  d:\ technical \ c ++ study \ readparsing \ readparsing \ timestamp.h(31):可以
  是'std :: istream&operator >>(std :: istream&,TimeStamp&)'1>
  在尝试匹配参数列表'(int,TimeStamp)'时


我在TimeStamp.h中有以下代码

#ifndef __TIMESTAMP_
#define __TIMESTAMP_

#include <iostream>

struct DateTime
{
    unsigned int dwLowDateTime;
    unsigned int  dwHighDateTime;
};


class TimeStamp
{
public:
    TimeStamp()
    {
        m_time.dwHighDateTime = 0;
        m_time.dwLowDateTime = 0;
    }

    TimeStamp& operator = (unsigned __int64 other)
    {
        *( unsigned __int64*)&m_time = other;
        return *this;
    }
private:
    DateTime        m_time;
};

std::istream& operator >> (std::istream& input, TimeStamp& timeStamp);

#endif


在main.cpp中,我有以下内容

#include <iostream>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#include "TimeStamp.h"

std::istream& operator >> (std::istream& input, TimeStamp& timeStamp)
{
    // 1.
    // use regular stream operator parsing technique to parse individual integer x values (separated in the form "xxxx-xx-xx xx:xx:xx.xxx")
    // for year, month, day, hour, minute, seconds, mseconds
    unsigned int year;
    unsigned int month;
    unsigned int day;
    unsigned int hour;
    unsigned int minute;
    unsigned int seconds;
    unsigned int milliSeconds;
    char dash;
    char colon;

    input >> year >> dash >> month >> dash >> day >> hour >> colon >> minute >> colon >> seconds >> colon >> milliSeconds;

    cout << "Time stamp opeator is called " << std::endl;

    // 2.
    // code to be written.

    return input;
}



int main () {

    std::string dateTime = "2012-06-25 12:00:10.000";

    TimeStamp myTimeStamp;

    std::istringstream issline(dateTime);

    issline >> myTimeStamp;


   return 0;
}

最佳答案

我认为您需要#include <sstream>才能使用istringstream

09-05 23:09