iostream

#include iostream in C?

余生长醉 提交于 2019-12-21 03:44:15
问题 In C++ we always put the following at the top of the program #include <iostream> What about for C? 回答1: Well, this is called the standard I/O header. In C you have: #include <stdio.h> It's not an analog to <iostream> . There is no analog to iostream in C -- it lacks objects and types. If you're using C++, it's the analog to <cstdio> . stdio man page GNU documentation on Input/Output on Streams See also this fantastic question and its answer, 'printf' vs. 'cout' in C++ 回答2: #include <stdio.h>

Sharing output streams through a JNI interface

匆匆过客 提交于 2019-12-21 03:37:33
问题 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 can I invoke Foo::print from Java so that the output appears on out ? Is there any way to coerce the OutputStream to a std::ostream in the JNI layer? Can I capture the output in a buffer the JNI layer and

How to convert image into hexa decimal bytes array to send it to output stream in iOS sdk

旧巷老猫 提交于 2019-12-20 15:23:23
问题 I wan to print an image on a bluetooth printer. I got some sample code by the printer manufacturer. Here is the code - unsigned char buffer3[796]={ 0x55 , 0x66 , 0x77 , 0x88 , 0x44 , 0x1B , 0x58 , 0x31 , 0x19, 0x20, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00

Why does ofstream(“log.txt”, ios::app|ios::trunc); always fail?

♀尐吖头ヾ 提交于 2019-12-20 10:44:20
问题 The following code was compiled with VC++ Nov 2012 CTP on Windows 7 x64. #include <fstream> using namespace std; int main() { ofstream fout("log.txt", ios::app|ios::trunc); if (!fout) { cout << "An error occurred!" << endl; // Always go here! Why? } } The cppreference.com website doesn't say that ios::app cannot be combined with ios::trunc . What are the exact semantics of ios::app and ios::trunc ? 回答1: The filebuf constructor to which these flags are passed † has behaviours based on those

Output error when input isn't a number. C++

点点圈 提交于 2019-12-20 05:47:24
问题 I am making a function that takes a number from the user's input and finds the absolute value of it. I want to make it return an error if the user inputs anything other than just a number. How would I go about doing that? (I know that this is probably an easy question for a lot of you, but I'm taking my first programming class in C++ so I know very little. Any help would be greatly appreciated.) 回答1: If you are actually trying to program in idiomatic C++, ignore the (intentionally?) bad

[原]tornado源码分析系列(六)[HTTPServer详解]

强颜欢笑 提交于 2019-12-20 04:24:06
引言:上一章讲了关于HTTPServer的原理,这一次通过分析源码来了解更多的细节 看看HTTPServer类的组织结构: HTTPServer的主要工作 一.提供了一些基础的比如说listen,bind此类共有操作 二.完成了一个 _handle_events()的公有回调函数,此函数是 IOLoop的基础,此函数为每一个连接创建一个单独的 IOStream 对象 三.start函数,启动HTTPServer,并设置相应的参数(如根据CPU个数来设置进程数等) 从HTTPServer类的构造函数可以看出,最重要的参数是设置回调函数,此回调函数用于处理request对象 每次有HTTP的请求,都会通过HTTPConnection 封装一个HTTPRequest对象,这个对象包含了HTTP请求的所有信息 所以在HTTPServer层,需要对这个对象进行一番处理后调用 request.write将结果返回给客户端 此回调函数会先注册到HTTPServer,然后注册到HTTPConnection 里面,因为request这个对象是由HTTPConnection对象产生 def _handle_events(self, fd, events): while True: try: connection, address = self._socket.accept() except

C++ match string in file and get line number

你。 提交于 2019-12-20 04:18:56
问题 I have a file with the top 1000 baby names. I want to ask the user for a name...search the file...and tell the user what rank that name is for boy names and what rank for girl names. If it isn't in boy names or girl names, it tells the user it's not among the popular names for that gender. The file is laid out like this: Rank Boy-Names Girl-Names 1 Jacob Emily 2 Michael Emma . . . Desired output for input Michael would be: Michael is 2nd most popular among boy names. If Michael is not in girl

C++ match string in file and get line number

我怕爱的太早我们不能终老 提交于 2019-12-20 04:18:53
问题 I have a file with the top 1000 baby names. I want to ask the user for a name...search the file...and tell the user what rank that name is for boy names and what rank for girl names. If it isn't in boy names or girl names, it tells the user it's not among the popular names for that gender. The file is laid out like this: Rank Boy-Names Girl-Names 1 Jacob Emily 2 Michael Emma . . . Desired output for input Michael would be: Michael is 2nd most popular among boy names. If Michael is not in girl

Long double is printed incorrectly with iostreams on MinGW

谁说我不能喝 提交于 2019-12-20 02:32:17
问题 Consider the code #include <iostream> int main() { std::cout << 4.2L; } Compiling it on MinGW and running results in the following output: > g++ test.cc > a.exe -7.89773e-278 Is it a bug in MinGW and is there a fix or workaround? Update: There is a similar issue with printf described in this question: #include <cstdio> int main() { std::printf("%Lg", 4.2L); // prints -7.89773e-278 } However, the issue with printf can be fixed by defining __USE_MINGW_ANSI_STDIO while this one can't, so I think

Effects on Input Variable after Failed Input Stream

依然范特西╮ 提交于 2019-12-20 02:32:15
问题 I was working on the following code. #include <iostream> int main() { std::cout << "Enter numbers separated by whitespace (use -1 to quit): "; int i = 0; while (i != -1) { std::cin >> i; std::cout << "You entered " << i << '\n'; } } I know that using while (std::cin >> i) would have been better but I don't understand a specific occurrence. If I provide an invalid input, the loop becomes infinite because the Input Stream enters a failbit state. My question is that what happens to the input