iostream

C++ having cin read a return character

半城伤御伤魂 提交于 2019-12-03 05:48:14
I was wondering how to use cin so that if the user does not enter in any value and just pushes ENTER that cin will recognize this as valid input. Martin Cote You will probably want to try std::getline : #include <iostream> #include <string> std::string line; std::getline( std::cin, line ); if( line.empty() ) ... I find that for user input std::getline works very well. You can use it to read a line and just discard what it reads. The problem with doing things like this, // Read a number: std::cout << "Enter a number:"; std::cin >> my_double; std::count << "Hit enter to continue:"; std::cin >>

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

情到浓时终转凉″ 提交于 2019-12-03 05:11:57
问题 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 2.653 2.653 2.653 2.654 2.658 2.669 2.669 2.667 2.666 2.666 2.664 2.663 2.663 2.663 2.662 2.663 2.663 2.663 2.663 2.663 2.663 2.662 2.660 2.656 2.657 2.657 2.657 2.654 2.653 2.652 2.651 2.648 2.647 2.646 2.642 2.641 2.637 2.636 2.636 2

iOS app with real-time updates from server: Socket (using streams) or Apple Push Notification service?

…衆ロ難τιáo~ 提交于 2019-12-03 05:08:44
问题 I'm trying to make an iOS 5 app that features real-time things coming from the server. It will only use these whilst the app is running. To make it real-time without polling I have been evaluating two design routes: Creating a socket from the app to the server, and exchanging information via streams. Pros: Relatively simple and would not involve a 3rd party. Cons: Battery life drain. For an overview of how this might work, check out this excellent tutorial: http://www.raywenderlich.com/3932

DataContractSerializer - how can I output the xml to a string (as opposed to a file)

安稳与你 提交于 2019-12-03 04:06:44
问题 I had a quick question regarding the datacontractserializer. Maybe it's more of a stream question. I found a piece of code that writes the xml to a filestream. I basically don't want the file and just need the string output. public static string DataContractSerializeObject<T>(T objectToSerialize) { var fs = new FileStream("test.xml", FileMode.OpenOrCreate); var serializer = new DataContractSerializer(typeof(T)); serializer.WriteObject(fs, objectToSerialize); fs.Close(); return fs.ToString();

Why do I have to press enter Twice?

社会主义新天地 提交于 2019-12-03 04:05:01
For some reason in my program when I reach a certain spot, I have to press Enter twice in order to get it to submit. I added the clear to keep it from skipping input and the ignore() to keep it from keeping any extra characters in the buffer. I enter my input and then it drops down to a new line, I hit Enter again and it enter the input and continues the program no problem but I'm wondering why. Here's a code snippet: cin.ignore(); cout << "Enter Student Major (ex. COSC): "; cin.getline(student.major, 6); for(int i = 0; i < sizeof(student.major); i++) student.major[i] = toupper(student.major[i

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

血红的双手。 提交于 2019-12-03 03:57:12
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 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00

customize cout

一个人想着一个人 提交于 2019-12-03 03:43:18
How can I derive a class from cout so that, for example, writing to it new_cout << "message"; would be equivalent to cout << __FUNCTION__ << "message" << "end of message" << endl; class Log { public: Log(const std::string &funcName) { std::cout << funcName << ": "; } template <class T> Log &operator<<(const T &v) { std::cout << v; return *this; } ~Log() { std::cout << " [end of message]" << std::endl; } }; #define MAGIC_LOG Log(__FUNCTION__) Hence: MAGIC_LOG << "here's a message"; MAGIC_LOG << "here's one with a number: " << 5; #define debug_print(message) (std::cout << __FUNCTION__ <<

Create an iostream using boost asio specifying ip and port

限于喜欢 提交于 2019-12-03 03:26:48
I have a problem concerning boost asio libraries. I successfully tried to create a socket between a client and a server, this involves creation of resolvers in order to specify ip and port to the server (the server only requires port) and other objects, but, most importantly, it is necessary to use write and read_some as functions to read and write from/in the socket. I would really appreciate to use a stream, and this is possible in boost asio, but that's strange... In almost all examples using streams, to create a server it is necessary to provide port, ok, let's talk about the client...

cout and cin are not functions, so what are they?

荒凉一梦 提交于 2019-12-03 03:20:12
问题 Generally in C programming language We consider printf and scanf to be functions. when it comes to cout and cin, in C++ what are they?I mean they cant be functions as they are not followed by parenthesis,so they are not functions. So what are cout and cin are standard input and output functions?OR something else? 回答1: std::cout and std::cin are global objects of classes std::ostream and std::istream respectively, which they've overloaded operator << and >> . You should read about operator

Set filename of the Pdf that is streamed back to the browser

不想你离开。 提交于 2019-12-03 03:13:25
I have a Java webapp creating a pdf and streaming it back to the browser. byte[] pdf = report.exportPdfToArray(user); response.setContentType("application/pdf"); response.setHeader("content-disposition", "inline; filename=\"My.pdf\""); outStream = response.getOutputStream(); outStream.write(pdf); outStream.flush(); outStream.close(); The report is executed and it is sent back to the browser, but I can not control the name of the file even though I set the content-disposition . I am using Jboss 4.2.1. Do you know what am I missing? EDIT : So is there any way to set the filename when the content