Linked Questions

37 votes
2 answers
4k views

The following code works fine, but why is this correct code? Why is the "c_str()" pointer of the temporary returned by foo() valid? I thought, that this temporary is already destroyed when bar() is ...
Frunsi's user avatar
  • 7,157
7 votes
3 answers
24k views

For Code: stringstream ss("012345678901234567890123456789012345678901234567890123456789"); some articles said it is wrong for followed usage due to ss.str return temp object and will destructered ...
jiafu's user avatar
  • 6,586
5 votes
2 answers
353 views

I have checkd gcc and clang and both does not generate any warnings. I suppose that lifetime of temporary from foo() will be prolonged untill the end of full expression which is where semicolon in bar ...
mike's user avatar
  • 1,740
5 votes
1 answer
149 views

Consider the following code, based on this answer: #include <iostream> #include <sstream> class StringBuilder { public: template <typename T> inline StringBuilder &operator&...
rainer's user avatar
  • 7,149
0 votes
0 answers
60 views

I'm assuming this is undefined behavior, but I'm not exactly sure why? When I compile the above code with g++ 4.4.7 and execute it: #include <iostream> #include <string> using namespace ...
MrMiserMeister's user avatar
224 votes
9 answers
578k views

My understanding is that string is a member of the std namespace, so why does the following occur? #include <iostream> int main() { using namespace std; string myString = "Press ENTER ...
Chunky Chunk's user avatar
  • 17.3k
-2 votes
3 answers
3k views

Consider the MWE below, std::string return_string() { return "this is a string" } int main() { const char *y = return_string().c_str(); std::string str = return_string(); const char *...
void life's user avatar
  • 170
0 votes
2 answers
172 views

I'm working on a software using a home-made report library which takes only (const char *) type as an argument : ReportInfo(const char* information); ReportError(const char* error); [...] As I'm ...
augustin-r's user avatar
2 votes
1 answer
759 views

Consider this MCVE: #include <boost/program_options.hpp> #include <iostream> #include <map> namespace po = boost::program_options; using namespace std; po::options_description ...
andreee's user avatar
  • 4,718
2 votes
1 answer
632 views

I came across some funny memory behavior working with numpy + cython, while trying to get data from a numpy array as a C array, to use in a GIL-free function. I've taken look at both the cython and ...
Anis's user avatar
  • 3,104
0 votes
1 answer
331 views

I'm trying to display a simple message within my first MFC application. Strangely, the first sample doesn't work, instead the second one works correctly. auto text = std::to_wstring(1).c_str(); ...
bit's user avatar
  • 973
1 vote
2 answers
376 views

I was getting intermittently weird results with running stat() (perror(): "Bad address") on a filename that comes from a commandline argument in my project: // mz.h class MzImage { private: ...
neuviemeporte's user avatar
-1 votes
2 answers
135 views

I have a C++ function that is supposed to repeat a string a certain amount of times. What I've seen is that when the resulting string is more than 15 characters long, the function does not return ...
CalSch's user avatar
  • 11
0 votes
2 answers
143 views

So I want to do something like printf("%s", '\t'*3); Im just wondering if there is a way to print something like that without looping
user1686896's user avatar
0 votes
1 answer
106 views

I'm extracting text from a PDF using Poppler and used the following code to print the text: for (std::vector<poppler::text_box>::iterator it = currpg.begin(); it != currpg.end(); ++it) { ...
c2po's user avatar
  • 13

15 30 50 per page