iostream

iostreams - Print `wchar_t` or `charXX_t` value as a character

丶灬走出姿态 提交于 2019-12-13 13:05:33
问题 If you feed a wchar_t , char16_t , or char32_t value to a narrow ostream, it will print the numeric value of the code point. #include <iostream> using std::cout; int main() { cout << 'x' << L'x' << u'x' << U'x' << '\n'; } prints x120120120 . This is because there is an operator<< for the specific combination of basic_ostream with its charT , but there aren't analogous operators for the other character types, so they get silently converted to int and printed that way. Similarly, non-narrow

Is it possible to get output of “tail -f” command to java programme?

烂漫一生 提交于 2019-12-13 12:28:17
问题 According to: Java IO implementation of unix/linux "tail -f" Java "tail -f" wrapper I assume its possible but I have the following problem. String TailCommand = "tail -f /path/PATH.txt| grep (...)"; Runtime r = Runtime.getRuntime(); Process p = r.exec(TailCommand); //handle buffer while (running) { // handle output } Process p terminates. It works fine with commands that doesnt have constant updates unlike "top" or "tail -f". I wonder if I missed something, there is some buffer limitations or

Phone number lookup within text file

我是研究僧i 提交于 2019-12-13 11:02:30
问题 Basically My Program Goal is that i have a file containing 4 telephone numbers it would Look Like this Harry Keeling (555)123-4567 Frank James (555)123-8901 Arthur Paul (555)987-4567 Todd Shurn (555)987-8901 What my program is doing right now is prompting the user for the name and last name and iterates through the file to see if their is a match if their is a match the phone number is saved in the variable phone number if their isnt a match the program outputs error right now my program is

std::ofstream won't write to file (sometimes) [closed]

梦想与她 提交于 2019-12-13 09:48:55
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I've gone over many questions with the same or similar titles, I have changed the code in so many ways I can't even count.... I have an interesting problem. I have a class for logging that is extremely simple and just writes stuff into a file. The exact same code works in the constructor, but will not work in

A generic print function

谁都会走 提交于 2019-12-13 06:49:59
问题 I don't have a good C++ book on hand and google pulls ups nothing useful. How does this work? Conceptually what is going on here? Technically, is the prototype for operator<<() predefined, how did the writer of this know how to write it so that << is overloaded to output Container values? Where can I go to look at the operator<<() so that I can overload it? Also for an input you need a start and an end "place" c.begin() , c.end() ...but for output you need one "place" ostream_iterator . This

std::codecvt::do_in method overloading vs the rest of base methods

假装没事ソ 提交于 2019-12-13 04:39:00
问题 I have overloaded do_in method of std::codecvt : #include <iostream> #include <locale> #include <string> class codecvt_to_upper : public std::codecvt<char, char, std::mbstate_t> { public: explicit codecvt_to_upper(size_t r = 0) : std::codecvt<char, char, std::mbstate_t>(r) {} protected: result do_in(state_type& state, const extern_type* from, const extern_type* from_end, const extern_type*& from_next, intern_type* to, intern_type* to_end, intern_type*& to_next) const; result do_out(state_type

C++ Extraction Operator for Class Functions

蹲街弑〆低调 提交于 2019-12-13 02:47:15
问题 I'm not sure if operator overloading is what I'm looking for, but I need to know the best way to achieve the following in C++; I have a class Employee (for simplicity) with just an ID number atm. Please assume the input file has an int number and some characters after (1 line shown only), such as: 1234 Charles Hammond Here is the code so far. I am trying to use the extraction operator to get the integer and other data from input file to my class function (SetID); class Employee { int

Can't redirect error stream from Cython

笑着哭i 提交于 2019-12-12 22:21:23
问题 The SFML library that I'm trying to cythonize defines this function below that allows to change where errors are printed to (by default SFML writes error messages to the console when this function is not called): namespace sf { std::ostream& err() { static DefaultErrStreamBuf buffer; static std::ostream stream(&buffer); return stream; } } My simplified .pxd file for the above function: cdef extern from 'SFML/System.hpp' namespace 'sf': ostream& cerr 'sf::err' () And my .pyx module, which

C++ output stream floating point call chain [closed]

泪湿孤枕 提交于 2019-12-12 20:13:06
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . In C++, when I do std::cout << 1.2; what is the actual chain of functions that are called to actually display the number? I realize this is compiler specific, but I am interested in particular with the Gnu

Output spits two extra control characters, possibly a memory corruption bug?

≯℡__Kan透↙ 提交于 2019-12-12 18:53:10
问题 I have the following program test.cc: #include <iostream> unsigned char bogus1[] = { // Changing # of periods (0x2e) changes output after periods. 0x2e, 0x2e, 0x2e, 0x2e }; unsigned int bogus2 = 1816; // Changing this value changes output. int main() { std::clog << bogus1; } I build it with: g++ -g -c -o test.o test.cc; g++ -static-libgcc -o test test.o Using g++ version 3.4.6 I run it through valgrind and nothing is reported wrong. However the output has two extra control characters and