iostream

Save file from byte array on servermap path

半城伤御伤魂 提交于 2020-01-14 03:39:07
问题 I Want to save a PDF file from a byte array and want to save that file on my server map path location. Below is my code snippet. It's giving no errors nor saving the file. You are welcome to correct my syntax if it is wrong or help me by referring other code snippets. byte[] data = (byte[])listDataset.Tables[0].Rows[0][0]; System.IO.FileStream file = System.IO.File.Create(Server.MapPath(".\\TmpImages\\"+hfFileName+".pdf ")); file.Write(data, 0, data.Length); file.Close(); 回答1: It could be a

Is possible to fix the iostream cout/cerr member function pointers being printed as 1 or true?

本小妞迷上赌 提交于 2020-01-13 05:21:26
问题 If you run the following: #include <iostream> int main() { std::cout.setf(std::ios::boolalpha); std::cout << &main << "\n"; std::cout << (void*)&main << "\n"; // The workaround return 0; } // prints something like // true // 0x55deee04189a If you remove the std::cout.setf(std::ios::boolalpha) call, it just prints 1 instead of true . If you look at the https://godbolt.org/z/6CFH3P assembly, you will notice that the C++ template resolution is choosing the boolean operator std::basic_ostream

Why do I have to press enter Twice?

此生再无相见时 提交于 2020-01-12 04:00:08
问题 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

customize cout

感情迁移 提交于 2020-01-12 03:23:05
问题 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; 回答1: 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

Value stored when istream read fails

巧了我就是萌 提交于 2020-01-11 11:10:08
问题 Sample code: #include <iostream> int main() { int x = 5; std::cin >> x; std::cout << x << '\n'; } On one particular implementation the following behaviour occurs: Input: 6 ; output 6 Input: a ; output: 0 Input: (end-of-file); output 5 Input: (whitespace followed by end-of-file); output 5 So, on failure, the cin >> x is assigning 0 to x if it was a failure to convert text to int; but it is not assigning 0 if the failure was due to end-of-file. Is this correct behaviour? If not, what is the

Java how to read folder and list files in that folder in jar environment instead of IDE

只谈情不闲聊 提交于 2020-01-10 02:03:35
问题 my problem is that I create a folder(name is IconResources) under src , in IconResources there are many pictures. Directory is like this: ProjectName src package 1 package 2 IconResources(this is the target folder) I want to list all picture files name and do something with those pictures. And I found that File.list() only works in IDE, if I export project to a jar to make a standalone, it cannot work. So I searched and found that I should use inputstream and outputstream. Now I find i/o

c++ fastest way to read only last line of text file?

☆樱花仙子☆ 提交于 2020-01-08 17:18:09
问题 I would like to read only the last line of a text file (I'm on UNIX, can use Boost). All the methods I know require scanning through the entire file to get the last line which is not efficient at all. Is there an efficient way to get only the last line? Also, I need this to be robust enough that it works even if the text file in question is constantly being appended to by another process. 回答1: Use seekg to jump to the end of the file, then read back until you find the first newline. Below is

stdio.h及cstdio的区别

 ̄綄美尐妖づ 提交于 2020-01-08 06:02:52
2013-07-04 16:45:19 找了很多资料,没有说的很明白的,下面是老外的一篇文章,解释的比较清楚,后面给出翻译。 Clarifying stdio.h versus cstdio 转自: http://forums.codeguru.com/showthread.php?344430-Clarifying-stdio-h-versus-cstdio I constantly see recommendations to #include <cstdio> instead of using stdio.h and the same for the other C headers. What most posters fail to mention is that this should put all the symbols into namespace std and NOT into the global namespace. This you have to write std::printf(...). Simply writing printf alone will not work . The same applies to the headers : cassert ciso646 csetjmp cstdio ctime cctype climits

Transcoding characters on-the-fly using iostreams and ICU

旧巷老猫 提交于 2020-01-06 08:36:13
问题 I'd like to transcode character encoding on-the-fly. I'd like to use iostreams and my own transcoding streambuf , e.g.: xcoder_streambuf xbuf( "UTF-8", "ISO-8859-1", cout.rdbuf() ); cout.rdbuf( &xbuf ); char *utf8_s; // pointer to buffer containing UTF-8 encoded characters // ... cout << utf8_s; // characters are written in ISO-8859-1 The implementation of xcoder_streambuf would use ICU's converters API. It would take the data coming in (in this case, from utf8_s ), transcode it, and write it

How to bypass a << calling as if “#ifndef DEBUG” macro in c++?

こ雲淡風輕ζ 提交于 2020-01-06 05:40:07
问题 I coded a little logging-lib for myself, and it accepts two forms calling. The one likes a normal function calling, the other likes a std::ostream << operator output. And then I defined a few of Macros respectively for every log-levels as following: #ifdef DEBUG #define LOG_DEBUG( strLogBody ) appendLog( leon_log::LogLevel_e::ellDebug, std::string( __func__ ) + "()," + ( strLogBody ) ) #define LOG_INFOR( strLogBody ) appendLog( leon_log::LogLevel_e::ellInfor, std::string( __func__ ) + "()," +