Reputation: 3172
In class I've been tasked at writing a method for an already defined class, and cannot change class definitions, header files, or #include statements.
I need to split a string into different variables using this code,
istringstream ss(line)
ss >> plu >> descp >> one >> price >> weight
How can I use istringstream when I cannot use #include < sstream>? Is there a way in c++ to directly call that method instead of #including it in the definitions?
I've tried,
istringstream::istringstream ss(line)
std::istringttream:istringstreeam ss(line)
std::istringstream ss(line)
And none of those compiled, I don't really know how including files works in C++.
Upvotes: 1
Views: 460
Reputation: 42083
How can I use istringstream when I cannot use
#include <sstream>
?
You can not.
Is there a way in c++ to directly call that method instead of #including it in the definitions?
If the definitions are not available, the compiler will not know what to do. It will not even know that the keywords that you are using refer to some types... istringstream
will be an undefined identifier.
Upvotes: 1
Reputation: 76240
How can I use istringstream when I cannot use #include < sstream>? Is there a way in c++ to directly call that method instead of #including it in the definitions?
Without copy and pasting the declaration of the std::istringstream
class from the <sstream>
header file into your file there's no way the compiler can know how much size to allocate for ss
. So I'd say: no, there's no easy workaround.
Upvotes: 3