179 Posted Topics
Re: Use the Contains method of the string class to find substrings. [code=csharp] string s = "Hello World!"; if ( s.Contains( "Hello" ) ) { Console.WriteLine( "Found \"Hello\" in the string" ); } [/code] | |
Re: It's not bad to do anything. Even global variables aren't bad. They can make it harder to troubleshoot or reuse your code, but saying they're bad is weird. You have the same issue with static variables. They're not right for a function that has to be re-entrant but it they … | |
Re: State means that info persists between calls. If you want to keep a running total of some statistic, that's state, and it's hard to maintain with functions. You have to use a global variable or a parameter. [code=cplusplus] int count1 = 0; void function( int& count2 ) { // do … | |
Re: [url=http://code.google.com/p/google-sparsehash/]This[/url] one's good. | |
Re: [QUOTE]I remember hearing that you have to ask cin to throw away the enter or something?[/QUOTE] Yeah something like that. Try adding cin.ignore like this. [code=cplusplus] cin >> choice; cin.ignore( 80, '\n' ); [/code] | |
Re: Just use the array name when you call your function. [code=cplusplus] getMove( move, space ); [/code] | |
Re: [QUOTE]i need a detail explanation how the program work[/QUOTE] Didn't you write it? :confused: | |
I'm writing a doubly linked list and a lot of the code ends up being the same with _next and _prev switched. What can I do to keep from writing some code with _next and then the same code again with _prev? Can I do like a template that flips … | |
Re: [QUOTE]That's as close as I can get without giving you the answer on a plate.[/QUOTE] Everybody doesn't think in code, and that example is pretty vague. [QUOTE]Will you please give me little detail hint?[/QUOTE] When you loop over a 2D array, you use two loops, right? One loop on the … | |
Re: From the prototype I'd guess this. [code=cplusplus] template<class T> void Stack<T>::Output(T element) { cout<< element; } [/code] I don't understand why you have a parameter. It seems you want to output the whole stack. [code=cplusplus] template<class T> void Stack<T>::Output() { for ( int i = 0; i < pool.size(); ++i … | |
| |
Re: [QUOTE]15 ISO C++ forbids declaration of `privite' with no type[/QUOTE] The error says it all. private is misspelled. | |
Re: You can't set the size of an array at run time. You have to dynamically create the array from a pointer. [code=cplusplus] typedef struct tagPredefinedStruct{ int iSize; int iCount; } PREDEFINEDSTRUCT; typedef struct APIStruct { int iNumber; PREDEFINEDSTRUCT *PreDefStruct; int iDate; } APISTRUCT; APISTRUCT api; int x; x = GetNumberofStructs(); … | |
Re: If you want to use variables in more than one method, you should make them member variables instead of local variables. | |
Re: I don't understand. I guess it depends on the data type of the variable that you're storing the bytes in. | |
Re: When you divide by 2 and the remainder is 0, the number's even. [code] if ( x % 2 == 0 ) { // even } else { // odd } [/code] | |
Re: Everything gets inherited and the public, protected or private accessibility just says if the derived class can use something or not. | |
Re: Is Cstring a class? If it lets you get an individual character and the size, you can do this easy. [code] char MiddleCharacter( Cstring string ) { return string[string.length() / 2]; } [/code] A char array string is the same way but you have to use strlen. [code] char MiddleCharacter( … | |
Re: [QUOTE]1) How can i get the size of the screen ? (not the forum, the screen borders)[/QUOTE] You can find that stuff in the [url=http://msdn2.microsoft.com/en-us/library/system.windows.forms.systeminformation_members.aspx]SystemInformation[/url] class. [QUOTE]2) How can i resize all the columns in a DataGridView to the length of their values ?[/QUOTE] The only sure way I know … | |
Re: System.String.Format lets you do that with the D and X formatters. [code=csharp] string decString = string.Format( "{0:D}", decValue ); string hexString = string.Format( "{0:X}", hexValue ); [/code] You can also just print the formatted values with Write or WriteLine because they use the same formatter strings. | |
Re: You can find out where the exe is with command line arguments. [code=cplusplus] #include <iostream> using namespace std; int main( int argc, char *argv[] ) { cout<< argv[0] <<endl; return 0; } [/code] Once you have that string, you can trim off the filename and then have a path for … | |
Is there a way to pass a function template to another function? I tried this but it doesn't work. [code=cplusplus] template <typename T> void template_function( T arg ) { } void function( template <typename T> void (*func)( T arg ) ) { } [/code] How can I pass a function … | |
I wrote this trying to understand templates, functors and inheritance. it works but I want to know if there's a better way. Is a base and derived class overkill for a sorting function? How cand I make it better? [code=cplusplus] /* sorting test Class based sorting by Kimberly Hamrick */ … | |
Re: [QUOTE]how could i change a pointer pointing to Personnel and have it point to Student?[/QUOTE] You can typecast it. [code] s = (Student*)person; [/code] | |
I was playing with a bunch of new things today and came up with this. Did I do anything wrong? [code=c++] /* binary class manipulator Print values or strings as binary by Kimberly Hamrick */ #include <iostream> // for C++ I/O #include <string> // for C++ strings using namespace std; … | |
Re: [QUOTE]Which process reads the data from it?[/QUOTE] All of them. :) Each process gets a handle to stdin and the computer makes sure that they all get a chance to read from it, but only one at a time. | |
I wrote strlen() for practice but it's really slow. Even if I copy the code from my compiler and run it, it's still slow. This is my test. [code=c++] /* strlen_comp Comparing my and Visual C++'s strlen by Kimberly Hamrick */ #include <assert.h> // for result tests #include <string.h> // … | |
Re: I bet there's an include path for libraries in the project settings. You should look there and see if you can find anything. | |
|
The End.