2012-06-28 44 views
0

我編譯下面的代碼並獲得以下錯誤C2440錯誤。如何解決這個問題?謝謝你的幫助。錯誤重載時輸出操作

錯誤C2079: 'issline' 使用未定義類 '的std :: basic_istringstream < _Elem,_Traits,_Alloc>' 1> 1>
[1> _Elem =炭,1>
_Traits = STD :: char_traits,1> _Alloc =標準::分配器1> 1> d:\技術\ C++研究\ readparsing \ readparsing \ main.cpp中(49):錯誤 C2440:初始化:不能從轉換'的std :: string」到‘INT’1> 無可用的用戶定義的轉換操作,可以執行這個 轉換,或操作員不能稱爲 1> d:\技術\ C++研究\ readparsing \ readparsing \ main.cpp(51):錯誤 C2678:二進制'>>':找不到操作符,其中包含'int'類型的左手操作數 (或者沒有可接受的轉換)1>
d:\ technical \ C++ study \ readparsing \ readparsing \ timestamp.h(31):可以 是 '的std :: istream的&操作>>(的std :: istream的&,時間戳&)' 1>
試圖匹配參數列表 '(INT,時間戳)'

我在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 
下面的代碼0

在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; 
} 
+0

反而是這個家庭作業?如果沒問題,我們只想知道。請標記爲這樣。 –

+0

不,它不是一門功課。我對項目的工作就如同代碼部分我需要做的,所以我說要寫入。 – venkysmarty

回答

1

您需要

#include <sstream> 

在main.cpp中。該錯誤消息說,您使用的是已被(向前)已宣告但尚未定義的類。通常這意味着你缺少一個包含。

注意#include <iosfwd>將在TimeStamp.h足夠的#include <iostream>