iostream

How to solve “Unresolved inclusion: <iostream>” in a C++ file in Eclipse CDT?

£可爱£侵袭症+ 提交于 2019-11-27 00:54:34
I download eclipse for c++ (cdt-master-8.0.2.zip). When I write: #include <iostream> It marks: Unresolved inclusion: <iostream> How can I fix it? Alan CN Go to Project > Properties > C/C++ General > Preprocessor Includes... > Providers and select " CDT GCC Built-in Compiler Settings ". I use Eclipse for cross compiling and I have to add the explicit directories for some of the standard C++ libraries. Right click your project and select Properties. You'll get the dialog shown in the image. Follow the image and use the + icon to explicitly add the paths to your C++ libraries. Make sure that your

Custom manipulator for C++ iostream

主宰稳场 提交于 2019-11-27 00:41:07
I'd like to implement a custom manipulator for ostream to do some manipulation on the next item being inserted into the stream. For example, let's say I have a custom manipulator quote : std::ostringstream os; std::string name("Joe"); os << "SELECT * FROM customers WHERE name = " << quote << name; The manipulator quote will quote name to produce: SELECT * FROM customers WHERE name = 'Joe' How do I go about accomplishing that? Thanks. It's particularly difficult to add a manipulator to a C++ stream, as one has no control of how the manipulator is used. One can imbue a new locale into a stream,

How to create a boost ssl iostream?

喜夏-厌秋 提交于 2019-11-27 00:30:09
问题 I'm adding HTTPS support to code that does input and output using boost tcp::iostream (acting as an HTTP server). I've found examples (and have a working toy HTTPS server) that do SSL input/output using boost::asio::read/boost::asio::write, but none that use iostreams and the << >> operators. How do I turn an ssl::stream into an iostream? Working code: #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> #include <boost/foreach.hpp> #include <iostream> #include <sstream> #include <string>

How to write custom input stream in C++

▼魔方 西西 提交于 2019-11-26 23:43:20
I'm currently learning C++ (Coming from Java) and I'm trying to understand how to use IO streams properly in C++. Let's say I have an Image class which contains the pixels of an image and I overloaded the extraction operator to read the image from a stream: istream& operator>>(istream& stream, Image& image) { // Read the image data from the stream into the image return stream; } So now I'm able to read an image like this: Image image; ifstream file("somepic.img"); file >> image; But now I want to use the same extraction operator to read the image data from a custom stream. Let's say I have a

Removing a comma from a c++ output

六眼飞鱼酱① 提交于 2019-11-26 23:37:20
问题 I wrote this program that sorts numbers in vectors from greatest to least, it works great but the only thing that is bugging me is trying to remove the comma from the last number. Heres my code #include <iostream> #include <vector> #include <cstdlib> #include <algorithm> using namespace std; int main() { vector<int> vi1, vi2, vi3; srand(987); for (int i = 0; i < 10; ++i) vi1.push_back(rand() % 10); sort(vi1.begin(), vi1.end()); for (int i = 0; i < 10; ++i) vi2.push_back(rand() % 10); sort(vi2

How to make cout behave as in binary mode?

让人想犯罪 __ 提交于 2019-11-26 23:14:15
Every time I do 'cout << endl' or even 'cout << "\n"' and then launch my program under Windows to output to a file ("a.exe < test.in > result.out") I get "\r\n" line endings in "result.out". Is there on earth a way to stop it doing so and just output "\n" on every 'cout << "\n"'? Thanks in advance. This works using Visual Studio 2013: #include <io.h> #include <fcntl.h> #include <iostream> int main( int argc, char * argv[] ) { _setmode( _fileno( stdout ), _O_BINARY ); std::cout << std::endl; } It will output only [0A], and not [0D][0A]. I don't believe you can force std::cout to output binary

c++ connect output stream to input stream

女生的网名这么多〃 提交于 2019-11-26 23:13:51
问题 What I would like to do is create a sort of "pipe" (like a pipe between processes), but between c++ iostreams within the same program. I have a function that requires an input stream as an argument, but my data is coming from an output stream. So is there a standard way to pipe the output of a std::ostream into the input of a std::istream ? 回答1: You can create a std::streambuf where the output goes to one buffer and std::overflow() blocks when the buffer becomes full. On the other end you'd

Wrap subprocess' stdout/stderr

假装没事ソ 提交于 2019-11-26 22:59:21
问题 I'd like to both capture and display the output of a process that I invoke through Python's subprocess. I thought I could just pass my file-like object as named parameter stdout and stderr I can see that it accesses the fileno attribute - so it is doing something with the object. However, the write() method is never invoked. Is my approach completely off or am I just missing something? class Process(object): class StreamWrapper(object): def __init__(self, stream): self._stream = stream self.

how to use isatty() on cout, or can I assume that cout == file descriptor 1?

落花浮王杯 提交于 2019-11-26 22:03:51
问题 Well, the subject says it all, basically. I have a command-line utility that may be used interactively or in scripts, using pipes or i/o redirection. I am using cin and cout for i/o, and I want to write an extra EOL at the end if the output is console, so that user prompt will start from the next line. Within scripts this would be harmful. Can I assume cin == 0, cout == 1 ? I understand that there is no clean way to get the file descriptor of a stream. Or is it? 回答1: It is possible to use

Why don't iostream objects overload operator bool?

旧时模样 提交于 2019-11-26 21:49:03
问题 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 returns a null pointer when the stream is bad (which can be implicitly converted to false ), and a non-null pointer otherwise (implicitly converted to true ). Why don't they just overload operator bool ?