473,508 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Temporary file with streams

Hello,

i want to build a UNIX-pipe-like file for temporary use with the C++
streams. First I want to write some data into, then read all that data out.
My attempt was this:

#include <iostream>
using namespace std;
int main()
{
char *buff = (char*) malloc(8096);
streambuf strbuf(buff, 8096);
istream istr(buff);
ostream ostr(istr.rdbuf());
istr << "HALLO Welt";
cout << ostr;
free(buff);
return 0;
}

Although the Visual C++ documentation states the constructor
streambuf( char* pr, int nLength );

the compiler responds, no function takes two parameters.

Has somebody an idea?

Thanks

Jenni


Jul 22 '05 #1
3 1858

"Jennifer Mauritz" <pr*****@is.very.important.respect.it> wrote in message
news:cn**********@beech.fernuni-hagen.de...
Hello,

i want to build a UNIX-pipe-like file for temporary use with the C++
streams. First I want to write some data into, then read all that data
out.
My attempt was this:

#include <iostream>
using namespace std;
int main()
{
char *buff = (char*) malloc(8096);
streambuf strbuf(buff, 8096);
istream istr(buff);
ostream ostr(istr.rdbuf());
istr << "HALLO Welt";
cout << ostr;
free(buff);
return 0;
}

Although the Visual C++ documentation states the constructor
streambuf( char* pr, int nLength );

the compiler responds, no function takes two parameters.

Has somebody an idea?

Thanks

Jenni

That constructor is in the <iostream.h>
#include <iostream.h>
int main()
Jul 22 '05 #2
Jennifer Mauritz wrote in news:cn**********@beech.fernuni-hagen.de in
comp.lang.c++:
Hello,

i want to build a UNIX-pipe-like file for temporary use with the C++
streams. First I want to write some data into, then read all that data
out. My attempt was this:

#include <iostream>
using namespace std;
int main()
{
char *buff = (char*) malloc(8096);
streambuf strbuf(buff, 8096);


std::streambuf aka std::basic_streambuf< char > only has a default
constructor and it is protected.

#include <iostream>
#include <sstream>

int main()
{
std::ostringstream ss;

ss << "hello world";

std::cout << ss.str() << '\n';
}

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #3
"Rob Williscroft" <rt*@freenet.co.uk> schrieb im Newsbeitrag
news:Xn**********************************@130.133. 1.4...
std::streambuf aka std::basic_streambuf< char > only has a default
constructor and it is protected.

#include <iostream>
#include <sstream>

int main()
{
std::ostringstream ss;

ss << "hello world";

std::cout << ss.str() << '\n';
}


Excellent!
Exactly what I looked for. And so easy...

Jenny
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3394
by: Marc Cromme | last post by:
I would like to ask a question about (good ?) style and possibilities in mixing C FILE* and C++ file streams. The background is that I want to use the C libpng library from within C++, but I...
3
2266
by: sb | last post by:
I think streams are nice, but what do you do when you have to write to or, even worse, read from a FILE*, for example a UNIX stream? C++ streams can not be created from FILE*'s or have them...
19
2465
by: Kai-Uwe Bux | last post by:
Hi folks, I have trouble writing a class, derving from stringstream, that collects item and once it's done will write them to std::cout in one go. It works fine except when I use it as a...
3
3472
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
6
4596
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
6
1663
by: Rob Nicholson | last post by:
What's the usual way of handling temporary user files under ASP.NET running on IIS? On a normal Windows client program, you'd probably store the documents in the %TEMP% folder. However, aren't all...
3
3016
by: sven.suursoho | last post by:
Hello, In main(), the first output API is what I try to achieve. Unfortunately it fails, printing first string as pointer instead of human readable message. Tried to initialize str(""), set new...
1
64004
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
2
2824
by: =?Utf-8?B?QXJ0?= | last post by:
I need to go through a folder and all of its subfolders and collect the Title, Comments, Keywords and a few other items. These are items that you see when you select a file in the Windows explorer...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.