Questions tagged [stdstring]

std::string is the C++ standard library's byte-based "string" type, defined in the header.

1177 questions
-3
votes
2 answers

Sizeof is a negative number when I try to find out the length of a string

In my code, I've been trying to find the length of a specific string in a string array. However, when I do it, no matter what method I try to find the length of the specific string, always returns -858993460 The code I've been working with is void…
JoeyChor
  • 63
  • 1
  • 7
-3
votes
1 answer

Assigning a std::basic_string to a string

I have the following existing class in my code: struct Aclass { typedef std::string TitleType; TitleType title; typedef std::size_t NumType; NumType some_num; }; After an instantiation of Aclass, let's say aclass, I set aclass.title…
Kevin
  • 16,549
  • 8
  • 60
  • 74
-3
votes
2 answers

C++ - Unable to convert from std::basic string to bool

I am trying to build a simple authentication mechanism whereby the user inputs his login credentials and his input is then compared to content in a file 'UserDB.txt'. However, when i try to iterate through the file and compare his credentials with…
Jared Aaron Loo
  • 668
  • 1
  • 10
  • 18
-4
votes
2 answers

Difference between string literal and string in cout statement?

What is the difference between the following ways of printing a string? std::cout << "hello"; // and std::cout << std::string("hello"); They both appear to do the same thing.
MaskOryle
  • 31
  • 4
-4
votes
3 answers

Why std::string seem to do something that std::is_convertible says isn't possible?

Why does std::to_string allow you to convert a double to std::string when std::is_convertible_v is false? For example: #include #include #include int main() { std::cout << "If double is " …
-4
votes
1 answer

This program return nothing

I am trying to write the following code so that it might return Hello, World!. using std::string; using namespace std; std::string hello() { return "Hello, World!"; } int main() { hello(); return 0; } having the code compiler run with 0…
-4
votes
2 answers

How to resolve declaration errors

I am attempting to run a code that takes a user inputted standard time and convert it to military time. For the user input, the hours can be typed as one or two digits, and AM/PM can be typed in any way. Given that, the code I have is as…
Cynderias
  • 5
  • 3
-4
votes
3 answers

std::string::find returns wrong answer

There are some posts concerning std::string::find (like this one here and this one too) but I have a somewhat different situation: #include #include int main(int argc, char **argv) { std::string haystack =…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
-4
votes
2 answers

Initialization of std::string from std::vector causes error

In C++ we can create a vector from another vector via std::vector tmp_1 { &some_vector[i] , &some_vector[j] }; Question : Is there any way to do the same for std::string? Something like: std::string tmp2 { &some_vector[i] ,…
Serhii S.
  • 51
  • 9
-4
votes
2 answers

get all the std::string's or first word's before character '='

I wanted to retrieve all the values/words before '=' Ex: A = my first variable, I wanted to get all the strings; var2 = I wanted to get this variable also; var3 = jcdksjfckjdsckjdscjkdsbckjdsncjsjd; Now I wanted to retrieve all the…
NDestiny
  • 1,133
  • 1
  • 12
  • 28
-4
votes
3 answers

'std::string' has no member named 'username' error

My code won't compile because of a 'std::string' has no member named 'username' error. I'm using code::blocks. I'm guessing the problem is because I'm trying to assign a string to a class, can someone help? #include #include…
Satki
  • 99
  • 2
  • 11
-4
votes
1 answer

Lack of Implicit Conversions for Strings and STL Containers

Why doesn't C++ have implicit conversion to bool defined for std::string and STL containers when writing code like if (!x.empty()) { ... } instead of more shorter if (x) { ... } when x is of type std::string or for example std::vector? I'm also…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
-5
votes
2 answers

hot to convert std::__cxx11::string to std::string

so i just want to convert int in digits and store it in array for eg int n=456; std::string nstr = std::to_string(n); std::cout << nstr[0]; now i just want the length of nstr... whenever i am using std::strlen(nstr); its giving an error **error:…
-5
votes
1 answer

Which string constructor is invoked?

I know this is initialization but I am confused which of the 2 constructors is invoked when a string literal is used in each case. Are they both copy constructors? string::string(const string& strString) string::string(const char…
softwarelover
  • 1,009
  • 1
  • 10
  • 22
-5
votes
1 answer

How does reversing a std::string in C++ works with this constructor?

std::string original; std::string reversed(original.rbegin(), original.rend()); I have found this method for reversing a std::string but I don't understand how it works. Can you provide me with an explanation?
John
  • 105
  • 10
1 2 3
78
79