- Strength to Increase Rep
- +5
- Strength to Decrease Rep
- -1
- Upvotes Received
- 3
- Posts with Upvotes
- 2
- Upvoting Members
- 3
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
21 Posted Topics
You can use a javax.swing.JFormattedTextField with a java.text.NumberFormat as the format. For example: [CODE]numberField = new JFormattedTextField(NumberFormat.getInstance());[/CODE]
When you build and run a project in Xcode, the executable is placed in the build/Debug (or build/Release) folder relative to the project directory.
Perhaps your compiler decided to optimize the code by substituting the contents of the function for the function call as if the function were declared inline.
As this is C++, you can use STL functions to do the work for you: [CODE]#include <algorithm> #include <iostream> int main() { int array[] = { 2, 5, 8, 1, 4, 2 }; size_t array_size = 6; std::cout << "Largest element: "; std::cout << *std::max_element(array, array + array_size); std::cout << …
I learned Java as my first programming language by reading Beginning Java by Ivor Horton. The book weights in at over 1000 pages. I found that an encyclopedic tutorial is an excellent way to learn your first language. I also read Accelerated C++ by Koenig and Moo having heard that …
[QUOTE=ArkM;646400]Well, we see unable to work (unable to compile) code sceleton. What's your problem?[/QUOTE] Read the comments in the input function.
There is no [i]operator[/i] for raising to powers in C++ similar to the ** operator in Python. You can do the multiplication or use the pow library function as suggested.
You are calling payroll::setvariables twice with 4 arguments, whereas the function definition specifies that it requires 7 arguments. In addition, you have not defined the function, only declared it.
Is there a difference, in terms of performance, between the two loops below? (myvec is type [icode]std::vector<int>[/icode].) [CODE]std::vector<int>::const_iterator pos; for (int i = 0; i < N; i++) { pos = myvec.begin(); // do something with pos }[/CODE] [CODE]for (int i = 0; i < N; i++) { std::vector<int>::const_iterator pos …
I did some searching on this topic but couldn't find anything definitive. Are basic types automatically initialized to 0 in C++ when allocated via [icode]new[/icode]? For example, are all values of nums guaranteed to be 0 in the code below? [icode]int *nums = new int[10];[/icode]
You can use the [icode]std::noskipws[/icode] stream manipulator to alter the behavior of the stream. See [URL=http://www.cplusplus.com/reference/iostream/manipulators/noskipws.html]here[/URL].
How about this: [icode]char *ns = malloc(l * sizeof(*ns));[/icode]
The default copy constructor should work for the Polynomial class below because it does not contain any dynamic data types. However, when I create a new Polynomial via the copy constructor, it prints 0 for the value of each coefficient. How can I fix this? [CODE]#include <iostream> #include <vector> class …
Alternatively you can use STL functions: [CODE]#include <string> #include <algorithm> ... std::string::iterator end_pos = std::remove(str.begin(), str.end(), '\'); str.erase(end_pos, str.end());[/CODE]
Like ruggedrat said, a breadth first search will suffice. Starting at M, mark each reachable node as distance 1; from those nodes, mark each reachable node [i]that has not already been visited[/i] as distance 2; etc: [CODE]##765# C###43 765432 6####1 54321M[/CODE] The shortest path is 8.
I have a template function as follows: template <typename T> int my_func(T& arg) T is expected to be of type map<T1, T2>. T1 is expected to be of a basic type (int, long, etc.) and T2 is expected to be of type vector<T1>/list<T1>/etc. I want to iterate over the contents …
If I declare a struct node, is the following legal in C++? [icode]node nodes_array[vector.size()];[/icode] I know this is not legal in C. However, my C++ compiler does not complain. Is this only in recent versions of C++, or has this always been legal in C++?
I am writing a chess game to familiarize myself with the C++ language. I have a Board class which contains a 2D array of pointers to Piece objects. I want to implement Board::operator[] such that the following is possible: [CODE]Board b; Piece *p = b[0][0];[/CODE] I could just return a …
[CODE]float fah = console.nextFloat();[/CODE]
An even better way to do this would be to create a Person class with the appropriate fields, and create a new class that implements Comparator for each desired sort order. See [URL=http://www.leepoint.net/notes-java/data/collections/comparators.html]here[/URL].
The End.