Все вопросы: [iostream]

74 вопросов

похожие теги: boost-iostreams
6
голосов
2ответов
2644 просмотров

stringstream temporary ostream return problem

I'm creating a logger with the following sections: // #define LOG(x) // for release mode #define LOG(x) log(x) log(const string& str); log(const ostream& str); With the idea to do: LOG("Test"); LOG(string("Testing") + " 123"); stringstream s; LOG(s << "Testing" << 1 <&...

10
голосов
3ответов
7564 просмотров

Are standard output streams in C++ thread-safe (cout, cerr, clog)?

I know that there is no concept of threads in current C++, but this article is saying: A typesafe, threadsafe, portable logging mechanism ..... The fprintf() function is threadsafe, so even if this log is used from different threads, the output lines won't be scrambled. Wh...

1
голосов
3ответов
455 просмотров

How can I make my char buffer more performant?

I have to read a lot of data into: vector<char> A 3rd party library reads this data in many turns. In each turn it calls my callback function whose signature is like this: CallbackFun ( int CBMsgFileItemID, unsigned long CBtag, void* CBuserInfo, ...

15
голосов
3ответов
4863 просмотров

Sharing output streams through a JNI interface

I am writing a Java application that uses a C++ library through a JNI interface. The C++ library creates objects of type Foo, which are duly passed up through JNI to Java. Suppose the library has an output function void Foo::print(std::ostream &os) and I have a Java OutputStream out. How...

4
голосов
2ответов
543 просмотров

How do I use basic_filebuf with element type other than char?

Say I want to read the contents of a file using basic_filebuf. I have a type called boost::uintmax_t which has a size of 8 bytes. I am trying to write the following: typedef basic_filebuf<uintmax_t> file; typedef istreambuf_iterator<uintmax_t> ifile; file f; vector<uintmax_t> ...

2
голосов
1ответов
567 просмотров

Is it ok to use wcout to print char*?

Consider this line: std::wcout << "Hello World!"; Is it OK to pass char* or char to wide stream?

2
голосов
6ответов
2783 просмотров

How do you output variable's declared as a double to a text file in C++

I am very new to C++ and I am wondering how you output/write variables declared as double to a txt file. I know about how to output strings using fstream but I cant figure out how to send anything else. I am starting to think that you can't send anything but strings to a text file is that correct...

23
голосов
10ответов
91254 просмотров

Alternative function in iostream.h for getch() of conio.h?

I'm trying to hold the screen on my output using the header file <iostream.h>, but I don't know any equivalent function to the getch() & clrscr() functions of <conio.h> in <iostream.h> or any other C++ library. Are there any such functions?

2
голосов
3ответов
180 просмотров

Performance problems when scaling MSVC 2005's operator&lt;<accross threads></accross>

When looking at some of our logging I've noticed in the profiler that we were spending a lot of time in the operator&lt;&lt; formatting ints and such. It looks like there is a shared lock that is used whenever ostream::operator&lt;&lt; is called when formatting an int(and presumably doubles). Upo...

3
голосов
2ответов
979 просмотров

custom data iostream

I have a data structure defined as struct myDataStruct { int32_t header; int16_t data[8]; } and I want to take a character stream and turn it into a myData stream. What stream class should I extend? I would like to create a custom stream class so that I can do things like myDataStruct...

9
голосов
3ответов
3696 просмотров

Why don't iostream objects overload operator bool?

In this answer I talk about using a std::ifstream object's conversion to bool to test whether the stream is still in a good state. I looked in the Josuttis book for more information (p. 600 if you're interested), and it turns out that the iostream objects actually overload operator void*. It re...

2
голосов
6ответов
2417 просмотров

Save stream to file

I have a fileupload control that allows users to upload images but before they can upload images I want to resize thomse images to mas 640x480 size the problem is I can't figure out what to do next. This is what I have; // CALL THE FUNCTION THAT WILL RESIZE THE IMAGE protected void btnUploadFile...

18
голосов
4ответов
8475 просмотров

How to read numbers from an ASCII file (C++)

I need to read in data files which look like this: * SZA: 10.00 2.648 2.648 2.648 2.648 2.648 2.648 2.648 2.649 2.650 2.650 2.652 2.653 2.652 2.653 2.654 2.654 2.654 2.654 2.654 2.654 2.654 2.654 2.654 2.655 2.656 2.656 2.657 2.657 2.657 2.656 2.656 2.655 2.655 ...

5
голосов
2ответов
1260 просмотров

Issue using SocketConnection with a Blackberry using MDS

I am currently writing an app on the Blackberry to do a simple send and receive of some raw data to another TCP based device on my network. I am having the same problem in the Blackberry simulator w/ an MDS simulator running and using a physical phone talking to my company's MDS server. Note this...

4
голосов
1ответов
289 просмотров

How to implement scoped iostream formatting?

I'd like to scope-limit the effect of I/O stream formatting in C++, so that I can do something like this: std::cout &lt;&lt; std::hex &lt;&lt; ... if (some_condition) { scoped_iofmt localized(std::cout); std::cout &lt;&lt; std::oct &lt;&lt; ... } // outside the block, we're now back to hex ...

11
голосов
3ответов
3771 просмотров

C++ fstream &lt;<and>&gt; operators with binary data</and>

I've always read and been told that when dealing with binary files that one should use read() and write() as opposed to the &lt;&gt; operators as they are meant for use with formatted data. I've also read that it is possible to use them, but it is an advanced topic, which I can't find where anyo...

1
голосов
1ответов
1444 просмотров

Locking files in windows

I am working on some legacy code which opens a file and adds binary data to the file: std::ifstream mInFile; #ifdef WINDOWS miWindowsFileHandle = _sopen(filename.c_str(), O_RDONLY , SH_DENYWR, S_IREAD); #endif mInFile.open(filename.c_str(), std::ios_base::binary); For...

3
голосов
1ответов
504 просмотров

Is there an elegant way to bridge two devices/streams in Asio?

Given two stream-oriented I/O objects in Asio, what is the simplest way to forward data from one device to the other in both directions? Could this be done with boost::iostreams::combination or boost::iostreams:copy perhaps? Or is a manual approach better--waiting for data on each end and then wr...

12
голосов
2ответов
6580 просмотров

Inheriting std::istream or equivalent

I need to bridge two libraries over a stream. QDataStream which is a stream from Qt and some function from another libraries that looks like this void read_something(istream&amp; i); I have no control over how the QDataStream is created and I'm not allowed to change the interface of read_so...

20
голосов
3ответов
34889 просмотров

Is it possible to read from a url into a System.IO.Stream object?

I am attempting to read from a url into a System.IO.Stream object. I tried to use Dim stream as Stream = New FileStream(msgURL, FileMode.Open) but I get an error that URI formats are not supported with FileStream objects. Is there some method I can use that inherits from System.IO.Stream th...

1
голосов
3ответов
1066 просмотров

read a int from a file wrote by java's writeInt method in C++?

How would one go about doing this? Also, is there an easy way to do it? Using a lib like Boost or something?

3
голосов
1ответов
1349 просмотров

C++ Boost io streams, error handling

Is it possible to make a custom stream work like the stanadrd ones in regard for errors? That is by default use the good/fail/bad/eof bits rather than exceptions? The boost docs only mention throwing an std::failure for stream errors and letting other error propagate (eg a badalloc from trying t...

7
голосов
5ответов
4716 просмотров

Binary version of iostream

I've been writing a binary version of iostreams. It essentially allows you to write binary files, but gives you much control over the format of the file. Example usage: my_file &lt;&lt; binary::u32le &lt;&lt; my_int &lt;&lt; binary::u16le &lt;&lt; my_string; Would write my_int as a unsigned 32...

9
голосов
5ответов
1914 просмотров

Is there a way to get non-locking stream insertion/extraction on basic_iostream in Windows?

I'm a C++ developer who has primarily programmed on Solaris and Linux until recently, when I was forced to create an application targeted to Windows. I've been using a communication design based on C++ I/O stream backed by TCP socket. The design is based on a single thread reading continuously f...

4
голосов
3ответов
8835 просмотров

Запись содержимого RichTextBox в файл

У меня есть RichTextBox, и я хочу сохранить текст в файл. Каждая строка RichTextBox заканчивается CR + LF ("\ n \ r"), но когда я сохраняю ее в файл, строки содержат только символ LF в конце. Если я скопирую содержимое в буфер обмена, а не в файл, все будет хорошо (в конце каждой строки содер...

3
голосов
2ответов
2371 просмотров

Как форматировать собственные объекты при использовании потоков STL?

Я хочу вывести собственный объект в поток STL, но с настраиваемым форматированием. Я придумал что-то вроде этого, но поскольку я никогда раньше не использовал locale и imbue, я понятия не имею, имеет ли это смысл и как реализовать MyFacet и оператор &lt; Мои вопросы: имеет ли это смысл и как р...

5
голосов
3ответов
7445 просмотров

ios :: nocreate ошибка при компиляции кода C ++

Пока собирали пакет, написанный на C ++ на RHEL 5.0. Я получаю следующую ошибку. &gt; ошибка: nocreate не является членом std::ios Исходный код соответствует: ifstream tempStr (argv[4],ios::in | ios::nocreate); Я пробовал # g ++ -O -Wno-deprecated -o а также: ...

1
голосов
2ответов
5358 просмотров

Boost asio ip tcp iostream Error Detection

Приветствую. Я только начинаю работать с библиотекой boost :: asio и на раннем этапе столкнулся с некоторыми трудностями, связанными с boost :: asio :: ip :: tcp :: iostream. Мой вопрос состоит из двух частей: 1.) Как подключить iostream, используя просто хост и номер порта? Я могу сдел...

15
голосов
2ответов
7458 просмотров

Почему std :: fstream устанавливает бит EOF именно так?

Недавно я столкнулся с проблемой, вызванной использованием fstream :: eof (). Я прочитал следующую строку здесь : Функция eof () возвращает true, если достигнут конец связанного входного файла, иначе false. и (ошибочно) предположили, что это означает, что если я использую fstream :: r...

17
голосов
4ответов
15690 просмотров

Обнаружение причины отказа при открытии офстрима, когда fail () истинно

Похоже, это должно быть просто, но я не нахожу этого в поиске в сети. У меня есть ofstream, который равен open(), и теперь fail() соответствует истине. Я хотел бы знать причину отказа открытия, например, с errno я бы сделал sys_errlist[errno].