std

Is it safe to return std::wstring from a DLL?

我们两清 提交于 2019-12-19 19:46:39
问题 According to some older StackOverflow questions ( Unable to pass std::wstring across DLL , C++ DLL returning pointer to std::list<std::wstring> ) it's not considered safe for a C++ DLL to return a std::wstring because there's no guarantee the main program has the same definition of std::wstring and therefore it might cause a crash. However, in http://en.cppreference.com/w/cpp/string/basic_string , it seems std::wstring can be used interchangeably with a WCHAR array now: (Since C++11) The

How to handle evolving c++ std:: namespace? e.g.: std::tr1::shared_ptr vs. std::shared_ptr vs. boost::shared_ptr vs. boost::tr1::shared_ptr

偶尔善良 提交于 2019-12-19 17:28:33
问题 For the code I am currently working on, we sometimes need to compile on some older systems with older compilers (e.g.- we run sims on an older IBM BlueGene/L, who's support contract dictates some quite old C++ compiler). The code itself makes use of shared_ptrs, and was originally written to use std::tr1::shared_ptr. When compiling on the old BlueGene machine, I quickly realized that it doesn't have a tr1:: implementation, and so I switched to boost::shared_ptr. Turns out there is also a

std::string, wstring, u16/32string clarification

本小妞迷上赌 提交于 2019-12-19 16:57:31
问题 My current understanding of the difference between std::string and std::wstring is simply the buffer's type; namely, char vs wchar_t , respectively. I've also read that most (if not all) linux distros use char for any and all strings, both ASCII as well as UTF, where Windows is the primary OS that uses wchar_t anymore. However, there are a few more string types that I want to get straight in my head: u16string and u32string , which are strings with 2-byte and 4-byte buffers, respectively. So,

“cout << cout” - what does the output stand for?

做~自己de王妃 提交于 2019-12-19 16:13:32
问题 After a long day of coding i accidentaly wrote cout << "some text" << cout; instead of cout << "some text" << endl; Now it printed out a memory address. What does it point to ? 回答1: std::cout is an instance of std::ostream , and, before C++11, that had a conversion operator to void*. It seems your code is triggering that conversion, giving you the address of the std::cout object. 来源: https://stackoverflow.com/questions/28872624/cout-cout-what-does-the-output-stand-for

“cout << cout” - what does the output stand for?

淺唱寂寞╮ 提交于 2019-12-19 16:13:23
问题 After a long day of coding i accidentaly wrote cout << "some text" << cout; instead of cout << "some text" << endl; Now it printed out a memory address. What does it point to ? 回答1: std::cout is an instance of std::ostream , and, before C++11, that had a conversion operator to void*. It seems your code is triggering that conversion, giving you the address of the std::cout object. 来源: https://stackoverflow.com/questions/28872624/cout-cout-what-does-the-output-stand-for

Why does the C++ stdlib rand() function give different values for the same seed across platforms?

一世执手 提交于 2019-12-19 12:24:23
问题 I understand that the rand() function generates pseudo-random numbers based on the seed it is given, and that on a given platform it will always generate the same sequence of numbers from the same seed, what I want to know is why it gives a different sequence across platforms that use the same library? I.e. how is rand() implemented? 回答1: The C++ standard does not specify what algorithm is used for the rand() function. The functionality is defined by whoever wrote the standard library on your

Copy of const char * using std::string constructor

帅比萌擦擦* 提交于 2019-12-19 11:22:44
问题 is this code ok? void SomeClass :: foo(const char * _name) { //name is of type const char * name = std::string(_name).c_str(); } it looks like it is working, but iam not sure if it is ok should i do an old school strcpy ? 回答1: It's ok since it compiles and doesn't cause undefined behavior. It's not ok since name points to an invalid memory after the statement completes execution. name = std::string(_name).c_str(); At the end of this statement the temporary std::string is destroyed and it

Using Namespace std

泄露秘密 提交于 2019-12-19 10:11:58
问题 I am taking a programming class in school and I wanted to start doing some c++ programming out of class. My school using Microsoft Visual C++ 6.0 (which is from 1998) so it still uses <iostream.h> rather than <iostream> and using namespace std . When I started working, I couldn't figure out how and when to use using namespace std and when to just use things like std::cout<<"Hello World!"<<'\n'; (for example) as well as it's limits and other uses for the namespace keyword. In particular, if I

Using Namespace std

南楼画角 提交于 2019-12-19 10:10:11
问题 I am taking a programming class in school and I wanted to start doing some c++ programming out of class. My school using Microsoft Visual C++ 6.0 (which is from 1998) so it still uses <iostream.h> rather than <iostream> and using namespace std . When I started working, I couldn't figure out how and when to use using namespace std and when to just use things like std::cout<<"Hello World!"<<'\n'; (for example) as well as it's limits and other uses for the namespace keyword. In particular, if I

Why std::vector does not have a release method?

爱⌒轻易说出口 提交于 2019-12-19 09:22:06
问题 I found myself in a situation where I would have liked to have an analog of unique_ptr 's release() for std::vector<> . E.g.: std::vector<int> v(SOME_SIZE); //.. performing operations on v int* data = v.release(); // v.size() is now 0 and the ownership of the internal array is released functionUsingAndInternallyDeletingRowPointer(data); Is there a particular reason why this kind of possibility is not provided? May that impose some constraint on std::vector 's the internal implementation? Or