Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I wanted to clear string from unwanted chars, and I tried to iterate it through a loop like this.
for(auto it=numer.begin(); it!=numer.end(); ++it)
{
if(*it=='-') numer.erase(it);
}
The error is: "expected primary-expression before '=' token";
I could, of course, I could do this with [] operator. But I am wondering why it doesn't work.
I appreciate your help.
If you want to remove all instances of a character from a string, a simple way to do that would be to use the standard erase-remove(if) idiom:
numer.erase(std::remove(numer.begin(), numer.end(), '-'), numer.end());
See also:
https://en.cppreference.com/w/cpp/string/basic_string/erase
https://en.cppreference.com/w/cpp/algorithm/remove
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
auto data = new char[480][640][3]();
char data = new char[480][640][3]();
First works.
Second doesnt.
Why? Isn't auto supposed to just replace itself with the type of the initializer?
Because the type isn't char. The type is char(*)[640][3] and the declaration would be written as
char (*data)[640][3] = new char[480][640][3]();
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
In C++, please explain meaning of string = "" in vector declaration -> vector<string = "">v;
Assuming these are std::vector and std::string, it is syntactically invalid. It won't compile.
Otherwise, you need to provide more context like: what are vector, string and v? Are they objects? Objects of what type? Are they macros? Are they classes? Are they templates? It could do anything. Here it prints Hello, World, here it calculates pi, here it creates a std::vector of std::string, and here it doesn't compile.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I think I saw something on using this to truncate test as a filter, but I've seen to no idea how to use it. Using as xx|do_trucate(20) gives the following:
TemplateAssertionError: no filter named 'do_truncate'
What is the correct usage?
Doh, from the spec I saw
do_trucate
http://code.nabla.net/doc/jinja2/api/jinja2/jinja2.filters.html
But in reality, its just truncate
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm attempting to create a vector of vectors of complex numbers, however it will not work, previous research indicates that the following should work
vector <vector <complex<double> > test(1,vector<complex<double> >(3));
it does not
I can't figure out why and I am going crazy trying to figure out why, I get the following error
error: template argument 1 is invalid
Can anyone figure out why?
You are missing one >:
vector<vector<complex<double> > > test(1, vector<complex<double> >(3));
// ^
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am sorting my vector of strings in the following way, so that I can binary_search it later.
std::vector<std::string> vec;
...........
...........
std::sort(vec.begin(),vec.end());
Now I am searching it as follows.
if (!std::binary_search(vec.begin(), vec.end(), "SomeString"));
{
//Not Found
}
else
{
//Found
}
However, it seems that the binary_search is not working, and it returns a false to the "strings" that are present in the vector.
What might I be doing wrong?
Look at the very last character on this line:
if(!std::binary_search(vec.begin(),vec.end(),"SomeString"));
You have a misplaced ; there. Remove it and test again.