Здравствуйте, Кодт, Вы писали:
К>Здравствуйте, Вов и К, Вы писали:
К>(2) и полиморфными объектами
К>Если ты решился делать всё через потоки (благо, для них уже много чего имеется в STL), обрати внимание: всё семейство operator<< принимает слева ostream. Это базовый класс, наследники которого — файловые и консольные потоки, но не только. Один из них — ostringstream — всё выводимое коллекционирует в строку.
К>К>Foo foo;
К>std::ostringstream oss;
К>oss << foo;
К>std::string s = oss.str();
К>
Это бы мне подошло конечно.
Но кмпилятор ругается при написании следующего кода:
struct Foo
{
int x;
double y;
char t[10]; // массив
};
Foo foo;
foo.x = 11;
foo.y = 22;
std::ostringstream oss;
oss << foo;
std::string s = oss.str();
d:\work\Debug\test\test.cpp(70) : error C2079: 'oss' uses undefined class 'std::basic_ostringstream<_Elem,_Traits,_Alloc>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
d:\work\Debug\test\test.cpp(70) : see reference to class template instantiation 'std::basic_ostringstream<_Elem,_Traits,_Alloc>' being compiled
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
d:\work\Debug\test\test.cpp(70) : see reference to class template instantiation 'std::basic_ostringstream<_Elem,_Traits,_Alloc>' being compiled
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
d:\work\Debug\test\test.cpp(71) : error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion)
d:\work\Debug\test\test.cpp(72) : error C2228: left of '.str' must have class/struct/union type
type is 'int'
Что я не так делаю?
Заранее прошу извинения за глупые вопросы. Я только начинаю вникать в С++ и STL