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 2 years ago.
Improve this question
Hello I am using c++ for this assignment.
If I have a string such as "P10" and I want to store the number 10 into an integer disregarding the P, how would I do that?
Assuming you only want to remove the first character from your string then
#include <string>
std::string str = "P10";
int i = std::stoi(str.substr(1));
Related
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 1 year ago.
Improve this question
vector<char> vec;
vec.push_back(0x1);
char* a = "qwe";
I want to push a to the end of the vector.
You can use the .insert() member function with pointers standing in as iterators.
vec.insert(vec.end(), a, a+strlen(a));
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 2 years ago.
Improve this question
I did various implementations but they take a long time
Can anyone give us the best implementation?
For example, add a ten-digit number to the end of a string
I did not find a good answer on the Internet
#include <iostream>
std::string a="string";
long n=1703705707;
a.append(std::to_string(n)); //becomes "string1703705707"
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 2 years ago.
Improve this question
I just have a general question. Can you have a string and an integer in one vector? I am planning to display card names and numbers. I want to display both and wanting the numbers to be added up at the end. Can I do this?
You can have std::string and int in one std::vectorusing std::variant
using ElementType = std::variant<std::string, int>;
std::vector<ElementType> v;
v.push_back(std::string("I am string"));
v.push_back(1);
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 3 years ago.
Improve this question
Say I have a string:
std::string x = "\\asdasd\\sewef\\sdvrhe\\"
How do I remove the double backslahes so that the string only contains single backslahes?
I need x string's value to be:
\asdasd\sewef\sdvrhe\
I am open to replacing chars or removing any method that achieves the desired result will be accepted.
"boost string algo" is your friend:
boost::replace_all(x, "\\\\", "\\");
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
I have a string which has a hastag/pound/octothorpe in it, and want it removed using a regex expression.
e.g.
iii <- '#lkdjljf, lkdflsdkf'
i would like a gsub(regex_bit_here,'',iii)
to remove the hastag/pound/octothorpe
Thanks
I have triedgsub("^#",'',iii), and it works