stdstring

How to create std::string from output stream?

谁都会走 提交于 2020-01-03 11:37:06
问题 Forgive the simple question, but I've been at this for hours, with no success. Im trying to implement a function: std::string make_date_string() I am using Howard Hinnant's date lib, which allows me to do stuff like this: cout << floor<days>(system_clock::now()); printing something like: 2017-07-09 I'm trying to figure out how I can get that output to go in a std::string so I can return it from my function, but Im getting nowhere. 回答1: I'm trying to figure out how I can get that output to go

Why setting null in the middle of std string doesn't have any effect

♀尐吖头ヾ 提交于 2020-01-02 08:05:33
问题 Consider #include <string> #include <iostream> int main() { /* hello 5 hel 3 */ char a[] = "hello"; std::cout << a << std::endl; std::cout << strlen(a) << std::endl; a[3] = 0; std::cout << a << std::endl; std::cout << strlen(a) << std::endl; /* hello 5 hel o 5 */ std::string b = "hello"; std::cout << b << std::endl; std::cout << b.length() << std::endl; b[3] = 0; std::cout << b << std::endl; std::cout << b.length() << std::endl; getchar(); } I expect std::string will behave identical to char

Error LNK2019: unresolved external symbol “toString(int)”

谁说胖子不能爱 提交于 2020-01-02 04:11:15
问题 Environment: Windows XP. Visual Studios 2010. Language - C++. I have run into the following link error & have run out of ideas how to fix this problem. I have a project (CnD Device) which links to 2 projects (Messages & Carbon) controlled by my group. I have tried to search for project properties between the 3 projects enter tcp_driver.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl toString(int)"

Error LNK2019: unresolved external symbol “toString(int)”

好久不见. 提交于 2020-01-02 04:11:09
问题 Environment: Windows XP. Visual Studios 2010. Language - C++. I have run into the following link error & have run out of ideas how to fix this problem. I have a project (CnD Device) which links to 2 projects (Messages & Carbon) controlled by my group. I have tried to search for project properties between the 3 projects enter tcp_driver.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl toString(int)"

GDB reports wrong address for parameter in c++ object's constructor

本秂侑毒 提交于 2020-01-02 02:34:29
问题 I'm experiencing a weird behavior with GDB passing a string as the parameter to a constructor. The code works fine, but when I step through in the debugger, GDB seems to think my parameter is at a different address then it is. Does anyone know what's going on here? Here's the simplest program I can create that demonstrates the problem: --(jwcacces@neptune)--------------------------------------------(/home/jwcacces)-- --$ nl gdb_weird.cpp 1 #include <iostream> 2 #include <string> 3 4 class C 5

C++11 case insensitive comparison of beginning of a string (unicode)

你离开我真会死。 提交于 2020-01-01 09:23:37
问题 I have to check if the particular string begins with another one. Strings are encoded using utf8, and a comparison should be case insensitive. I know that this is very similar to that topic Case insensitive string comparison in C++ but I do not want to use the boost library and I prefer portable solutions (If it is 'nearly' impossible, I prefer Linux oriented solutions). Is it possible in C++11 using its regexp library? Or just using simple string compare methods? 回答1: The only way I know of

Substring of a std::string in utf-8? C++11

夙愿已清 提交于 2019-12-30 06:48:29
问题 I need to get a substring of the first N characters in a std::string assumed to be utf8. I learned the hard way that .substr does not work... as... expected. Reference: My strings probably look like this: mission:\n\n1億2千万匹 回答1: I found this code and am just about to try it out. std::string utf8_substr(const std::string& str, unsigned int start, unsigned int leng) { if (leng==0) { return ""; } unsigned int c, i, ix, q, min=std::string::npos, max=std::string::npos; for (q=0, i=0, ix=str.length

Substring of a std::string in utf-8? C++11

落爺英雄遲暮 提交于 2019-12-30 06:47:06
问题 I need to get a substring of the first N characters in a std::string assumed to be utf8. I learned the hard way that .substr does not work... as... expected. Reference: My strings probably look like this: mission:\n\n1億2千万匹 回答1: I found this code and am just about to try it out. std::string utf8_substr(const std::string& str, unsigned int start, unsigned int leng) { if (leng==0) { return ""; } unsigned int c, i, ix, q, min=std::string::npos, max=std::string::npos; for (q=0, i=0, ix=str.length

How do I use 3 and 4-byte Unicode characters with standard C++ strings?

社会主义新天地 提交于 2019-12-30 00:05:13
问题 In standard C++ we have char and wchar_t for storing characters. char can store values between 0x00 and 0xFF . And wchar_t can store values between 0x0000 and 0xFFFF . std::string uses char , so it can store 1-byte characters only. std::wstring uses wchar_t , so it can store characters up to 2-byte width. This is what I know about strings in C++. Please correct me if I said anything wrong up to this point. I read the article for UTF-8 in Wikipedia, and I learned that some Unicode characters

Value and size of an uninitialized std::string variable in c++

倖福魔咒の 提交于 2019-12-28 12:49:31
问题 If a string is defined like this std::string name; What will be the value of the uninitialized string "name" and what size it would be? 回答1: Because it is not initialized, it is the default constructor that is called. Then : empty string constructor (default constructor) : Constructs an empty string, with a length of zero characters. Take a look : http://www.cplusplus.com/reference/string/string/string/ EDIT : As stated in C++11, §21.4.2/1 : Effects: Constructs an object of class basic_string