creating streams

May 4, 2010 at 1:47pm
I want to create a stream for input and output, but without using an fstream or iostream, just something I can use the .peek() and .get() functions with.

Is there a way to get a stream that doesn't have any orientation?
May 4, 2010 at 1:50pm
There is, but you still have to open/close etc on them. It all depends on what stream you mean. The object isn't designed to bloat you code, it's designed to help you use different kinds of streams correctly with an identical syntax.
May 4, 2010 at 2:10pm
Naturally. An example of how I want to use a stream is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
void toArabic(char from[], int& to){
	ofstream out("H:\\Files\\blah.txt");
	for(unsigned int g=0; g<=strlen(from);g++)
		out<<from[g];
	out.close();
	ifstream in("H:\\Files\\blah.txt");
	char cur;

	while(!in.eof()){
		cur=in.get();
		switch (cur){
			case 'M':to+=1000;break;
			case 'C':
				switch(in.peek()){
					case 'M':to+=900;in.get();break;
					case 'D':to+=400;in.get();break;
					default:to+=100;break;
				}break;
			case 'D': to+=500;break;
			case 'X':
				switch(in.peek()){
					case 'C':to+=90;in.get();break;
					case 'L':to+=40;in.get();break;
					default:to+=10;break;
				}break;
			case 'L':to+=50;break;
			case 'I':
				switch(in.peek()){
					case 'X':to+=9;in.get();break;
					case 'V':to+=4;in.get();break;
					default:to+=1;break;
				}break;
			case 'V':to+=5;break;
		}
	}
	in.close();
}


the fact that in and out are assigned to files is completely irrelevant to the code.
So I want it to store the data into one stream where I can access it, without it doing other stuff (making a file).
Last edited on May 4, 2010 at 2:15pm
May 4, 2010 at 2:23pm
May 4, 2010 at 3:11pm
That's what istream and ostream are, streams who's details are obscured because you don't want to care.

That's why when you provide << and >> operators for streams you specify ostream/istream and not an ifstream/istringstream or any concrete stream.

You need to think more about your interface as you actually have an interface problem.
Topic archived. No new replies allowed.