Type: Posts; User: laserlight
Search took 0.18 seconds.
Declare it before the main function definition, then call it as per normal, e.g.,
In a larger program, this declaration of f would go into a header fine.
No, call the function in the main function, not define it in the main function. Furthermore, you need to call it at the right place.
You did not call the find_e function (which you named f) in the main function.
Just checking: did you teacher stress to you that global variables should be avoided?
Please post your well formatted code in
bbcode tags. Does this program work correctly?
Create a second map or use boost::bimap.
October 17th, 2014, 02:10 PM
You have to do linear search, i.e., loop over the mapped values one by one and compare. I believe that std::find_if can be used (i.e., you need to provide a comparator that will compare the mapped...
October 17th, 2014, 12:32 PM
It compiles for me. I only received this warning:
test.cpp: In function ‘int main()’:
test.cpp:20:10: warning: unused variable ‘lettr’ [-Wunused-variable]
char lettr = 'e';
But this is not...
October 16th, 2014, 12:53 PM
Perhaps you wanted to declare one of the two operator overloads to be a const member function?
October 16th, 2014, 08:55 AM
It seems to me that Perceptualdiff is a tool that is unrelated to C++ in general, so it is unreasonable to suppose that the users who frequent this forum will be familiar with it such that we can...
October 16th, 2014, 08:51 AM
That would be a problem, yes. But mindlessly treating "all iterators for that container are invalid after an erase" as invalid is not a best practice to defend against such a 'bright' programmer....
October 15th, 2014, 12:16 PM
Not for std::map. As 2kaud implied, erase for std::map was changed in C++11 to return an iterator instead of void.
You probably saw an example for std::vector. (EDIT: oh, std::list would be more...
October 15th, 2014, 11:47 AM
No, it depends on the container. It is best to check what iterators (and references and pointers) will be invalidated rather than just assume that all of them will be. In the case of std::map only...
October 13th, 2014, 12:26 PM
There is no need to do that. The class template from the standard library is named complex, not Complex, so there is no name collision to begin with. Even if there was a name collision, it would be...
October 12th, 2014, 12:31 PM
operator<< should be declared to be a non-member function with two parameters:
std::ostream& operator<< (std::ostream &stream, const Complex &nr);
Since it has access to the private member...
October 10th, 2014, 11:32 PM
When you read into n using formatted input with operator>> the newline from entering the input remained in the input buffer. This newline was then read by getline, resulting in str being an empty...
October 10th, 2014, 01:22 AM
What was the error message?
October 10th, 2014, 12:51 AM
You could do this with a spreadsheet program: insert the contents as two columns, delete the first column, tranpose to rows, then export as CSV.
If you would rather write a program/script, then...
October 9th, 2014, 10:46 PM
In what way was it strange?
Besides, it might be strange to you, but someone else here who has seen it or otherwise understands it might not find it strange.
October 5th, 2014, 08:45 AM
C++11 refers to the 2011 edition of the C++ standard, which is the document, published in 2011, that defines the standard version of C++ (at least until the next edition is published, most probably...
October 5th, 2014, 04:51 AM
Yes. You can refer to the phrasing in the standard:
October 5th, 2014, 04:07 AM
"If a base of class D is private, its public and protected member names can be used only by the members of D."
What this means is that if you have a class like this:
September 25th, 2014, 02:48 AM
What material are you using to learn C++? It should cover this at some point.
September 25th, 2014, 02:25 AM
Ah, emplace_back was introduced in C++11. The idea is to directly construct at the back of the vector an element with the given arguments supplied to the relevant constructor, without involving any...
September 25th, 2014, 12:52 AM
Since C++11, there are two versions of push_back, one with a const lvalue reference parameter, the other with an rvalue reference parameter. Both only take one argument though, so your #1 looks...
September 24th, 2014, 11:14 PM
Perhaps you should look into using std::string. This way, you can read the string using formatted input with operator>> (if it does not contain whitespace) or with std::getline (if it could contain...
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.