stringstream

Why doesn't `std::stringstream::stringstream(std::string&&)` exist?

十年热恋 提交于 2019-12-03 10:27:08
问题 I was hoping stringstream has a constructor that steals its initial content from a string&& . Do such inter-species "move constructors" generally not exist in the STL? If not, why not? 回答1: There's history, which is disappointing. But also a future that looks bright. When move semantics went into C++11, it was huge, controversial, and overwhelming. I wanted to be able to move strings into and out of stringstream . However the politics at the time demanded that the internal store did not have

Copy data from fstream to stringstream with no buffer?

血红的双手。 提交于 2019-12-03 09:27:02
问题 Is there anyway I can transfer data from an fstream (a file) to a stringstream (a stream in the memory)? Currently, I'm using a buffer, but this requires double the memory, because you need to copy the data to a buffer, then copy the buffer to the stringstream, and until you delete the buffer, the data is duplicated in the memory. std::fstream fWrite(fName,std::ios::binary | std::ios::in | std::ios::out); fWrite.seekg(0,std::ios::end); //Seek to the end int fLen = fWrite.tellg(); //Get length

stringstream overflow at 4GB

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm having trouble getting beyond 4GB limitation for stringstream, even though it is running on a 64bit linux box with enough memory. The test code below (revised after reading your comments) core dump after 4GB. From the gdb trace, stringstream uses the default std::char_traits where int_type is set to 32bit int, rather than 64bit size_t. Any suggestion to work around? #include <stdint.h> #include <iostream> #include <sstream> #include <math.h> using namespace std ; int main ( int narg , char ** argv ) { string str ; stringstream

Writing stringstream contents into ofstream

人盡茶涼 提交于 2019-12-03 05:23:52
问题 I'm currently using std::ofstream as follows: std::ofstream outFile; outFile.open(output_file); Then I attempt to pass a std::stringstream object to outFile as follows: GetHolesResults(..., std::ofstream &outFile){ float x = 1234; std::stringstream ss; ss << x << std::endl; outFile << ss; } Now my outFile contains nothing but garbage: "0012E708" repeated all over. In GetHolesResults I can write outFile << "Foo" << std:endl; and it will output correctly in outFile . Any suggestion on what I'm

how copy from one stringstream object to another in C++?

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have stringstream object ss1 now I would like to create another copy from this one. I try this std :: stringstream ss2 = ss1 ; or std :: stringstream ss2 ( ss1 ) neither works The error message is like this std::ios::basic_ios(const std::ios &) is not accessible from bsl::basic_stringstream, bsl::allocator>::basic_stringstream(const bsl::basic_stringstream, bsl::allocator>&). 回答1: Indeed, streams are non-copyable (though they are movable). Depending on your usage, the following works quite well: #include #include int main () {

Android NDK STL c++_shared w/LIBCXX_FORCE_REBUILD results in std::stringstream NOP

匿名 (未验证) 提交于 2019-12-03 02:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: tl;dr: The question is for an explanation for why std::stringstream "fails", and why it fails in the way it does (by simply doing nothing), when linking to a rebuilt c++_shared library. A minimal example: std::stringstream ss; ss << "Hello World"; __android_log_print(ANDROID_LOG_INFO, "APP", "Length: %i", ss.str().size()); When compiling the project with APP_STL := c++_shared LIBCXX_FORCE_REBUILD := true The output is Length: 0 . When using APP_STL := c++_static or LIBCXX_FORCE_REBUILD := false , the stringstream works as expected, with

C++ stl stringstream direct buffer access

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: this should be pretty common yet I find it fascinating that I couldn't find any straight forward solution. Basically I read in a file over the network into a stringstream. This is the declaration: std :: stringstream membuf ( std :: ios :: in | std :: ios :: out | std :: ios :: binary ); Now I have some C library that wants direct access to the read chunk of the memory. How do I get that? Read only access is OK. After the C function is done, I dispose of the memorystream, no need for it. str() copies the buffer, which seems

c++ stringstream is too slow, how to speed up? [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Possible Duplicate: Fastest way to read numerical values from text file in C++ (double in this case) #include #include #include #include #include #include using namespace std ; static const double NAN_D = numeric_limits :: quiet_NaN (); void die ( const char * msg , const char * info ) { cerr > x ). fail ()) die ( "unrecognized numeric data" , str . c_str ()); return x ; } int main () { string str ( "12345.6789" ); clock_t tStart , tEnd ; cout strtod: 405 sstream: 1389 update: remove undersocres, env: win7+vc10 回答1: C/C++ text to

std::stringstream vs std::string for concatenating many strings

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I know one of the advantages of std::stringstream is that it is a std::istream so it may accept input from any type that defines operator<< to std::istream , and also from primitives types. I am not going to use operator<< ; instead I am just going to concatenate many strings. Does the implementation of std::stringstream make it faster than std::string for concatenating many strings? 回答1: There's no reason to expect std::string 's appending functions to be slower than stringstream 's insertion functions. std::string will generally be nothing

Why doesn't `std::stringstream::stringstream(std::string&&)` exist?

﹥>﹥吖頭↗ 提交于 2019-12-03 00:55:02
I was hoping stringstream has a constructor that steals its initial content from a string&& . Do such inter-species "move constructors" generally not exist in the STL? If not, why not? There's history, which is disappointing. But also a future that looks bright. When move semantics went into C++11, it was huge, controversial, and overwhelming. I wanted to be able to move strings into and out of stringstream . However the politics at the time demanded that the internal store did not have to be a basic_string<charT> . For example the internal store could be a vector . And there was no ability to