DataType of inFile ??

Hi there,

I'm working on a project, and here is some of my code.
I copied this code, because hopefully everyone can get the general idea what's going on. The originally code is working correctly, but I want to make a small adjustment. Now the vi.data is getting his information from the testfile.txt: inFile>>vi.data;

But I don't want to make use of a testfile anymore, but just a string.
So my question is now: What datatype does inFile has? or what datatype does vi.data need???

Greetings Espresso
Last edited on
inFile is an ifsteam, if you want you can replace it with a stringstream
1
2
3
4
5
6
7
stringstream ss("some text 123");
string s,t;
int i;
ss >> s >> t >> i;
//s == "some"
//t == "text"
//i == 123 

http://www.cplusplus.com/reference/iostream/stringstream/
Last edited on
Hi Bazzy,

That's the idea! But I get the following two errors:
[C++ Error] Unit4.cpp(66): E2450 Undefined structure 'stringstream'
[C++ Error] Unit4.cpp(66): E2034 Cannot convert 'char *' to 'stringstream'

1
2
stringstream ss("vertex3");
ss>>vi.data;


Could it be, that vi.data is expecting a different data type?
You have to include <sstream>
if vi.data has an istream &operator >> overloaded, it will work
Oke, that worked well.

Now I'm trying to call the function d.Read(ss) in the main() function.
But I get this error:
[C++ Error] Unit4.cpp(381): E2125 Compiler could not generate copy constructor for class 'ios'
[C++ Error] Unit4.cpp(381): E2247 'ios_base::ios_base(const ios_base &)' is not accessible

This is the code:

1
2
3
4
5
6
7
8
9
10
11
12
#include <sstream> 

using namespace std;

template <class DataType> 
class Graph
{

        public:
        void Read2(stringstream ss);

};


1
2
3
4
5
template <class DataType>
void Graph<DataType>::Read2(stringstream ss)
{
   ss>>vi.data; 
}


1
2
3
4
5
6
7
8
9
int main()
{

        stringstream ss("Vertex1 Vertex2 Vertex3");

        Graph<string> d;
        d.Read2(ss);            // HERE I GET THE ERRORS
}






streams don't have the copy constructor so you have to pass them by reference
Read2(stringstream &ss)
Last edited on
Topic archived. No new replies allowed.