Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
304 views

When should I delete the std::string returned from std::smatch inside a regex iterator, if at all?

I'm new to C++, and I have been playing around with its standard regex library. I made this proof of concept search function based on the following reference. https://en.cppreference.com/w/cpp/regex/...
martian17's user avatar
  • 508
1 vote
0 answers
288 views

rvalue and lvalue of std::string

i ran the code as shown and i am confused as to why a+b is a rvalue. From what i know, rvalue should only have a data or address and in such a case std::string should be a lvalue isn't it? void foo(...
Iberico's user avatar
  • 182
0 votes
1 answer
184 views

Why is std::string range constructor giving me an error macro passed 2 arguments, but takes just 1? [closed]

I have these two iterators that are used by the Boost parser: std::string equationToParse = "some_text"; std::string::const_iterator iter = equationToParse.begin(); std::string::...
David Moreno's user avatar
1 vote
1 answer
252 views

Why can't compilers optimize-out this std::string construction?

Consider the following code: #include <string> #include <cstring> size_t foo(const char* cptr) { if (cptr == nullptr) { return 0; } return strlen(cptr); } size_t bar() { ...
einpoklum's user avatar
  • 130k
3 votes
2 answers
103 views

Ambigous integer assignment to string c++

So, while playing around with C++, I did this: #include <iostream> int main() { std::string s{"someThing"}; std::cout << " s is: " << s << '\n'; s = 97; std::...
tkhurana96's user avatar
0 votes
0 answers
226 views

C++ printf no longer works after declaring an std::string

I'm trying to set up a new dev environment (Cygwin64 on Windows 7) and the following test code is not working: #include <stdio.h> #include <string> int main(int argc, char *argv[]) { ...
echawkes's user avatar
  • 477
2 votes
0 answers
402 views

C++ program with string class fails before main() breakpoint is hit, remove the string variable and it works as expected

My environment is Windows 10 Cygwin64 g++ 5.2.0 The following program works as expected (main executes without error, returns 0) #include <iostream> #include <string> using namespace ...
Jonathan Cano's user avatar
1 vote
0 answers
214 views

Segmentation fault on global std::string variables with g++ 3.4 and g++ 4.7

I have the following code: main.cpp #include <string> #include <iostream> using namespace std; string getString(); int main() { cout<<getString()<<endl; return 0; } mylib....
Mahmoud's user avatar
  • 81
3 votes
1 answer
979 views

std::string initialization with a bool

Consider the following initialization: std::string falseString = false; std::string trueString = true; With g++ 5.2.0, compiler throws a warning for falseString, while an error for trueString. With ...
CinCout's user avatar
  • 9,609
1 vote
2 answers
2k views

The procedure entry point could not be located [duplicate]

I'm trying to compile a C++ program with MinGW on Windows 10, but I keep receiving the following error (-Wall and -Werror are activated): The procedure entry point ...
Josh Grosso's user avatar
  • 2,104
-3 votes
3 answers
728 views

memcpy on new std::string implementation (gcc 5.1)

I have written the following code which seems to be working fine with old std::string implentation. But with gcc 5.1, it crashes. #include <string> #include <iostream> #include <...
Rahul Agrawal's user avatar
0 votes
2 answers
124 views

c++ compiler error using g++ -c: compiler recognizes a const string& as int

i created a class Products that has the constructor Product::Product(const int &num,const float &pr,const std::string &str): number(num),price(pr),name(str) { } i have the declaration in ...
Shahak Shama's user avatar
1 vote
0 answers
276 views

Why g++/clang do not support std::basic_string<T>::replace with const_iterators?

As I've found in the latest standard draft and on cppreference.com std::basic_string<T>::replace could be called with const_iterators as its arguments (for example in its second form where part ...
Predelnik's user avatar
  • 5,236
1 vote
1 answer
903 views

Different behavior of boost::serialization of strings on text archive

I'm having some issue serializing a std::string with boost::serialization on a text_oarchive. AFAICT, I have two identical pieces of code that behaves differently in two different programs. This is ...
Avio's user avatar
  • 2,699
1 vote
1 answer
997 views

c++ compare std::string won't work if I don't compile with Code::Blocks but cygwin

I'm coding a class that should read OFF Files and I'm having the following issue: If I compile it within the Code::Blocks environment everything works fine. If the first line of the file that is to ...
user1525814's user avatar
1 vote
1 answer
2k views

Why does not std:string + int give compilation error?

We just found our colleague thought he can add an integer to std::string and used such operation here and there in his code. We don't see any compiler error for this operation and I don't understand ...
jackhab's user avatar
  • 17.7k
4 votes
2 answers
3k views

Reference-counting of std::string

I'm looking at the code for basic_string (that is bundled with g++ 4.2.1). The copy constructor makes use of a grab() function to "grab" a copy of a string (increment its reference-count): _CharT* ...
Paul J. Lucas's user avatar
12 votes
3 answers
7k views

Avoiding improper std::string initialization with NULL const char* using g++

A there any g++ options which can detect improper initialization of std::string with NULL const char*? I was in the process of turning some int fields into std::string ones, i.e: struct Foo { ...
pachanga's user avatar
  • 3,063
3 votes
2 answers
3k views

Invalid free while performing a std::string assign with -O2 set in g++

Before I get blasted on opening another question, this question is related to another question that I opened a few days ago: C++ Program Always Crashes While doing a std::string assign After ...
bbazso's user avatar
  • 2,039