Reputation: 11441
I am compiling following code and getting following error. How to fix this? Thanks for your help.
error C2079: 'issline' uses undefined class 'std::basic_istringstream<_Elem,_Traits,_Alloc>' 1> with 1>
[ 1> _Elem=char, 1>
_Traits=std::char_traits, 1> _Alloc=std::allocator 1> ] 1>d:\technical\c++study\readparsing\readparsing\main.cpp(49) : error C2440: 'initializing' : cannot convert from 'std::string' to 'int' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1>d:\technical\c++study\readparsing\readparsing\main.cpp(51) : error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion) 1>
d:\technical\c++study\readparsing\readparsing\timestamp.h(31): could be 'std::istream &operator >>(std::istream &,TimeStamp &)' 1>
while trying to match the argument list '(int, TimeStamp)'
I have following code in 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
In main.cpp I have following
#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;
}
Upvotes: 0
Views: 340
Reputation: 3460
You need to
#include <sstream>
in main.cpp. The error message says that you are using a class that has been (forward) declared but not defined. Usually that means you are missing an include.
Note that #include <iosfwd>
would suffice in TimeStamp.h instead of #include <iostream>
Upvotes: 1
Reputation: 21351
I think you need to #include <sstream>
to use istringstream
.
Upvotes: 3