cout

mycout automatic endl

别说谁变了你拦得住时间么 提交于 2019-12-18 16:12:35
问题 I'd like implement class MyCout , which can provide possibility of automatic endl, i.e. this code MyCout mycout; mycout<<1<<2<<3; outputs 123 //empty line here Is it possible to implement class with such functionality? UPDATE: Soulutions shouldn't be like that MyCout()<<1<<2<<3; i.e. they should be without creating temporary object 回答1: This is simply a variant of Rob's answer, that doesn't use the heap. It's a big enough change that I didn't want to just change his answer though struct

mycout automatic endl

只谈情不闲聊 提交于 2019-12-18 16:12:23
问题 I'd like implement class MyCout , which can provide possibility of automatic endl, i.e. this code MyCout mycout; mycout<<1<<2<<3; outputs 123 //empty line here Is it possible to implement class with such functionality? UPDATE: Soulutions shouldn't be like that MyCout()<<1<<2<<3; i.e. they should be without creating temporary object 回答1: This is simply a variant of Rob's answer, that doesn't use the heap. It's a big enough change that I didn't want to just change his answer though struct

How do I use for_each to output to cout?

試著忘記壹切 提交于 2019-12-18 10:28:36
问题 Is there a more straight-forward way to do this? for_each(v_Numbers.begin(), v_Numbers.end(), bind1st(operator<<, cout)); Without an explicit for loop, if possible. EDIT: How to do this for std::cin with a std::vector if possible? (How to read n elements only)? 回答1: You could achieve this using std::copy into a std::ostream_iterator: std::vector<int> v_Numbers; // suppose this is the type // put numbers in std::copy(v_Numbers.begin(), v_Numbers.end(), std::ostream_iterator<int>(cout)); It

c++, cout and UTF-8

丶灬走出姿态 提交于 2019-12-18 05:49:12
问题 Hopefully a simple question: cout seems to die when handling strings that end with a multibyte UTF-8 char, am I doing something wrong? This is with GCC (Mingw) on Win7 x64. **Edit Sorry if I wasn't clear enough, I'm not concerned about the missing glyphs or how the bytes are interpreted, merely that they are not showing at all right after the call to cout << s4 (missing BAR). Any further cout s after the first display no text whatsoever! #include <cstdio> #include <iostream> #include <string>

Multiplying a string by an int in c++

ⅰ亾dé卋堺 提交于 2019-12-18 05:22:33
问题 What do I have to do so that when I string s = "."; If I do cout << s * 2; Will it be the same as cout << ".."; ? 回答1: No, std::string has no operator * . You can add (char, string) to other string. Look at this http://en.cppreference.com/w/cpp/string/basic_string And if you want this behaviour (no advice this) you can use something like this #include <iostream> #include <string> template<typename Char, typename Traits, typename Allocator> std::basic_string<Char, Traits, Allocator> operator *

Is it possible to cout an EM DASH on Linux and Windows? (C++) [duplicate]

别等时光非礼了梦想. 提交于 2019-12-18 05:17:08
问题 This question already has answers here : Output Unicode to console Using C++, in Windows (4 answers) Closed 4 years ago . I haven't been able to find a way to cout a '—' character, whether I put that in the cout statement like this: cout << "—"; or use char(151) , the program prints out a fuzzy undefined character. Do you guys see anything wrong with my code? Is cout ing a EM DASH even possible? Edit: I've also tried wcout << L"—"; and std::wcout << wchar_t(0x2014); . Those both print nothing

Correctly over-loading a stringbuf to replace cout in a MATLAB mex file

99封情书 提交于 2019-12-18 03:36:09
问题 MathWorks currently doesn't allow you to use cout from a mex file when the MATLAB desktop is open because they have redirected stdout. Their current workaround is providing a function, mexPrintf, that they request you use instead. After googling around a bit, I think that it's possible to extend the std::stringbuf class to do what I need. Here's what I have so far. Is this robust enough, or are there other methods I need to overload or a better way to do this? (Looking for portability in a

Using the console in a GUI app in windows, only if its run from a console

白昼怎懂夜的黑 提交于 2019-12-17 19:31:01
问题 My application is a GUI app that has helpful (though optional) information through the terminal (via cout). In Windows I either have a console appear (by compiling as a console app, or allocating it dynamically) or I don't. My intention is to make use of the console IF it is being run from the console, but ignore the console completely if it was not. (Essentially what happens in Linux and OS X). I do not wish to redirect to a file (and in the case of using cin, this is not a viable solution

printf more than 5 times faster than std::cout?

狂风中的少年 提交于 2019-12-17 18:52:50
问题 #include <iostream> #include <cstdlib> #include <cstdio> #include <ctime> int main(int argc, char* argv[]) { std::clock_t start; double duration; std::cout << "Starting std::cout test." << std::endl; start = std::clock(); for (int i = 0; i < 1000; i++) { std::cout << "Hello, World! (" << i << ")" << std::endl; } duration = (std::clock() - start) / (double) CLOCKS_PER_SEC; std::cout << "Ending std::cout test." << std::endl; std::cout << "Time taken: " << duration << std::endl; std::system(

iguana::json/xml 序列化框架

限于喜欢 提交于 2019-12-17 18:08:49
环境:win10 vs2017 c++17 boost 1、下载源码: https://github.com/qicosmos/iguana 2、创建工程,包含源码目录、boost库目录;boost库;c++17 //json结构模板 struct person { std::string name; int age; }; REFLECTION(person, name, age) struct one_t { int id; }; REFLECTION(one_t, id); struct two { std::string name; one_t one; int age; }; REFLECTION(two, name, one, age); struct composit_t { int a; std::vector<std::string> b; int c; std::map<int, int> d; std::unordered_map<int, int> e; double f; std::list<one_t> g; }; REFLECTION(composit_t, a, b, c, d, e, f, g); void test_json() { person p; const char * json = "{ \"name\" : \"tom\", \