What is the meaning of this expression [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I am trying to push a integer that is stored in a string to a stack of type int I was trying to do the same by using stack.push(str[i]) which resulted in some weird values in the final outcome
Github copilot suggeted to do it this way which was succesfull
else
{
temp.push(exp[i]-'0');
}
what is the meaning of -'0' here

The char '0' has ascii value 0x30 (48 decimal).
The char '9' has ascii value 0x39 (57 decimal).
If you do '9' - '0' = 57 - 48 = 9.
So you are converting a digit from its ascii number '9' = 57 to its numeric value 9.
This is often used when fast-converting a string of integers to its numeric value.

Related

Regex for these strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm having difficulty catching some strings. I want a regex to catch the strings in this list:
1
2
3
4
5
6
7
8a
8b
8c
8d
9
There will only be a letter after the number 8, and 8 will always have a following letter (a-d). The rest of the numbers will not have a letter following them.
Thanks
You can use:
[1-7]|9|8[abcd]
Depending on whether you want the whole string to match, so that nothing else follows or precedes the match, you may need to add anchors:
^([1-7]|9|8[abcd])$
Or, alternatively, if you just want to match digits that are not followed by a letter (a, b, c, d) except when it is 8 (where it is required), then:
([1-7]|9)(?![abcd])|8[abcd]

Do you use single or double quotes when defining char variables in C++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have two questions actually
I am trying to do encryption in C++ using the XOR operation. When i encrypt any two characters i get the ? as the encrypted character why is that?
Here is a sample of my code Xoring a and b.
#include<iostream>
using std::cout;
using std::cin;
int main()
{
char x='a';
char y='b';
char d=x^y;
cout<<"a xor b = "<<d<<"\n";
return 0;
}
When you output characters which are not printable (and below the 'space' which is 32, most of them are) you are getting question mark or square depending on where you do it. To see the integer value of the XOR, replace d with (int)d

How can I convert a string to a byte array? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I convert a string to a byte array in C++?
For example, "Hello" → 48 65 6c 6c 6f.
I'm trying to pattern search the memory with this byte array after.
std::string::c_str() yields the underlyng c string / byte array.
Also see std::string::c_str() for a list of occasions when the returned pointer might be invalidated (basically everytime you modify the string and of course when the std::string itself is destroyed).
You can create a copy of it using memcpy() if required.

Filter input amount at specific points in regex? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How would someone do something like this in regex...
^[A-Za-z0-9]{1,254}+#$
[A-Za-z0-9]{1,254} Indicates ,
any character of: 'A' to 'Z', 'a' to 'z',
'0' to '9'
(between 1 and 254 times
(matching the most amount possible)),
Edit: If you need # at the end try with the regex [A-Za-z0-9]{1,254}#

what are the input cases for the following requirement [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
what are the input cases for the following requirement (should cover boundary values and equivalence class):
X can take values from 0 to 100 where X is a signed 8 bit integer.
Input values for a boundary test case in this case are -1, 0, 100, 101.
If X is unsigned then the "equivalent class" boundary test case should have as input: 0, 100, 101.
I am not sure if you want to the test the boundaries of number representation, in this case 8 bits. So you should also test for signed 127 or 128 and unsigned 255. But it depends on representation of the signed numbers .