560 Posted Topics
Re: Question #1. It's a C++ template, which is a powerful feature. Question #2. You have two variables with the same name in the same scope. That's a no-no in every programming language I know of. | |
Re: [quote] myMatrix[j] = new myClass[yDimension]; // "error C2512: 'myClass' : no appropriate default constructor available" // Set the pointer to NULL - is this necessary? myMatrix[j] = NULL; [/quote] You should set it to NULL before allocating memory, and after deleting the memory. No that's not necessary there. you could … | |
Re: Anybody feel like checking out the TR1 random number generation facilities? I think it will let you specify a larger range. | |
Re: I'm assuming the pointers point to dynamically allocated data, probably allocated with "new" ? In that case, it is very important you do not lose track of the pointers that point to data allocated with "new". When you copy a pointer to the vector that has pointers in it, if … | |
Re: There is most likely a warning level you can set to have the compiler only display more critical warnings. [url]http://www.cplusplus.com/reference/string/getline/[/url] | |
Re: in this header file are useful character manipulation functions: [url]http://www.cplusplus.com/reference/clibrary/cctype/[/url] and on a random side note, I would set the loop up like this: [code] while( fin.get(c) ) { if( c == '\n' || c == '\r' )//<-- not guaranteed to work. lines++; //... } [/code] \r is the carriage … | |
Re: Using Visual Studio the exception class has a constructor overload with a C string as it's parameter. G++/GCC do NOT have that overload. So blame Microsoft's compiler, then convert your exceptions to std::string. [b] also this is absolutely WRONG! [quote]void main()[/quote] [/b] [b] Use instead [code]int main()[/code] [/b] [i] Please … | |
Re: [code] void Add(DataType p_item) { int m_newSize = m_size+1; DataType* tempArr = new DataType[m_newSize]; for(int i=0;i<m_size;i++) tempArr[i] = m_array[i]; tempArr[m_size] = p_item; m_size = m_newSize; if(m_array!=0) delete[] m_array; m_array = tempArr; tempArr = 0; }[/code] Well there are some serious problems with this. I expected your class to be something … | |
Re: [url]http://msdn.microsoft.com/en-us/library/dd144879%28v=VS.85%29.aspx[/url] Google'd it. | |
Re: [quote] usingstd: :cout: usingstd: :cin: usingstd: :end1: usingstd: :setw: [/quote] Surely you meant: [code] using std::cout: using std::cin: using std::endl: using std::setw: [/code] But since your program is so small it would be wise to: [icode] using namespace std; [/icode] ! This shall not pass: [quote] cout << end1 << … | |
Re: Probably some input left in the stream. There are tutorials for avoiding this. Which is probably the best idea if you want to know what's going on. Otherwise you can use my method: [code] int someInt = 0; cin >> someInt; //<- if the user bunks this up and //enters … | |
Re: Microsoft Visual Studio 2010 file. If you can re-build the project and link your runtime to the .exe statically that should fix it. (change an option in the project settings) Otherwise, you can try putting the debug dll in the same folder as the .exe, or one directory above it … | |
Re: may want to initilize the static variable to 0 to start with. It will have a positive value while instances of the class exist, otherwise 0. | |
Re: I am familiar with neither, though I have used many a C++ library, and using only one or at the most two different libs will help maintain flexibility and minimize problems with the project. I would try to use only one, if possible. | |
Re: woah woah woah, what's going on here? If you want a function to modify a variable as an argument to the function you can either pass by pointer or by reference. In this case you could also return the value. pass by reference: [code] void GetChar(char &ch) { cin >> … | |
It may have only been Visual C++ 6.0 or something, but I think I remember needing to add curly braces after a switch's case label to declare variables, is this still true with VS2010 and C++? ex: [code] switch( 1 ) { case 1: { int a; //<-- ok } … | |
I'm a college student, about to have an associates degree and start working on my Bachelor's for CS. I have a project that I've been working on for a while now, and I'm thinking about making it open source, and hosting it on sourceforge. The reason I would do so, … | |
Re: He's using a 20 year old compiler that has a header file called "graphics.h", the compiler he's using probably produces 16 bit executables and supports non-standard C++. Ahh the amazing Turbo C++, it's still used in universities, typically in India. Though, this poster's profile says Pakistan. I would recommend OP … ![]() | |
Re: You could try implementing the sieve of eratosthenes using a vector<bool> or a bitset, the wikipedia page on the sieve is decent; the vector<bool> is for marking it as not prime. The indices would be the numbers. [url]http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes[/url] You also have other options, of course. It is my belief that … | |
Re: Do you mean sort the characters of each string, or sort the array of strings? std::sort() [url]http://www.cplusplus.com/reference/algorithm/sort/[/url] | |
| |
Re: If your compiler has C++0x TR1 support, you can use the auto keyword for the type, otherwise you can use the iterator type. I'm not exactly sure what you want, but here is an example of iterating over a set with iterators. If iterators are new to you, you may … | |
Re: My suggestion (while maybe not the best, but is simple), is: [code] #include <iostream> #include <string> using namespace std; int main() { const string ping_command = "PING "; string input; cout << "Enter IP: "; getline(cin, input);//<-- gets a line of input into "input" string command = ping_command + input; … | |
Re: Random suggestion: could typedef your array so as to help ensure consistency. [code] typedef char matrix_type[100][50]; int foo(matrix_type m); [/code] | |
Re: Yes that is indeed a pointer to a function, a named one. [code] typedef void (*funcPtrType)(int someParam); funcPtrType pSomeFunc = nullptr; pSomeFunc = &someFuncWithTheRightParamsAndReturnType; pSomeFunc(1000); [/code] | |
Re: It's not managed C++ anymore, it's C++/CLI--there is a difference. managed C++ had the horrible syntax, C++/CLI is actually kind of decent. | |
Re: Sometimes data is left in the buffer of cin. check cin for !good(), cin.good() is not the exact opposite of cin.bad(). good() will return true if no error bits are set, false otherwise. Afterward you will want to clear() the errors bit, and sync() the buffer associated with the stream … | |
Re: I would also like to add that the input stream is not checked for errors in the example you have been given, so if you type a letter when it expects a number it will probably cough & die or cough & infinite loop. | |
Re: I think the stl container template, std::vector<T> will help you with the dynamic allocation, and the STL algorithm std::random_shuffle() will help you obtain new matrices--as for the random number generation, if you have C++0x TR1 support on your compiler, you can use the new random number generation facilities which includes … | |
Re: to make more readable: Functional decomposition, which involves breaking the program into segments and using functions for them. For instance, getting your input could be in it's own function. Personally I would probably use an array of floats and enum values for indexing it. ex: [code] enum //<-- anonymous enum … | |
Re: Also, the functions in <cctype> may be helpful. particularly isspace() and isalnum(). #include <cctype> | |
Re: The reference for the DrawText function says it's a pointer to a RECT structure, [url]http://msdn.microsoft.com/en-us/library/dd162498%28v=vs.85%29.aspx[/url] The reference for the RECT structure says it's four LONG variables, [url]http://msdn.microsoft.com/en-us/library/dd162897%28v=vs.85%29.aspx[/url] So you can make a RECT like this: [code] RECT drawingArea; memset(&drawingArea, 0, sizeof(RECT)); drawingArea.top = 0; drawingArea.left = 0; drawingArea.right = 150; … | |
Re: This is not the appropriate place to beg for code. | |
Re: If you're using Windows... Research some Windows API functions. If memory serves me, you'll want to enumerate the processes then it may be required that you get the path to the executable. [url]http://msdn.microsoft.com/en-us/library/ms682623%28v=vs.85%29.aspx[/url] | |
Re: The problem is here: [code] class PaintHandler{ }; [/code] That shouldn't be in your source file. | |
Okay, so the problem is: I need a way to display a graphic with a few lines of text over the picture. An amount determined at run-time of these will be created. They also needs to be contained in a scrollable container, and scroll properly. It sounds simple but I'm … | |
Re: Yeah you could make a notes application, or a scheduler which would alert the user at a certain time, etc. and when you say "third year" does that mean you're on year 3/4 for a bachelor's degree? I would make something useful to yourself, I have a few of them. | |
Re: [quote]I have to write a code[/quote] Okay, well then these pages will be helpful for you: [url]http://www.cplusplus.com/reference/iostream/fstream/[/url] [url]http://www.google.com/search?q=Clear+console+screen+in+C%2B%2B&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a[/url] Oh shi** my power is going out. | |
If a U.S. government agency were to infect a PC with a virus, would it be possible to detect it with personal anti-virus software? If so, what's the best bet software wise? | |
| |
How are iterators used in C# ? suppose I have say: [code] List<int> someList = new List<int>(); /* assume some items are added here */ /* and now I wonder if C++ style iterators are available? */ for( var i = /* iterator begin of list */ ; i != … | |
Re: The most likely reason they don't like .NET is because of vendor dependence, namely .NET code only working on Windows. The majority of the world uses Windows, and if you fear that may change, or you like Linux oh so much then you should steer clear of it. | |
Re: I think you will have to use a stream manipulator for that, I forget which one, maybe std::ios::fixed or std::ios::setprecision. They're in <iomanip>. [url]http://www.cplusplus.com/reference/iostream/manipulators/[/url] You can set the output stream to display leading zeroes, but my question is why do you want the zero to be shown? | |
Re: Oh yeah, I had a problem with that when I was first learning C++ too. = assigns to whatever is on the left side of it. | |
C++/CLI @ runtime add a PictureBox to a tab control, I need to do this at run-time because they're to represent some data the user must be able to manipulate. I actually need them to be in some kind of scrollable panel on the tabcontrol. Any ideas? | |
Re: Hmm, well.. here you can assign a name to a function pointer... [code] typedef void (*someFunc)(int param); someFunc func_pointer = nullptr; [/code] | |
Re: This may be helpful for you (Windows only): [url]http://msdn.microsoft.com/en-us/library/ms810467.aspx[/url] This may also be helpful: [url]http://www.libusb.org/[/url] | |
Hello, I thought I was doing things right when I created a delegate to call a function to access the container's data, but it still throws an exception. I have something similar to: [code] public ref class myform : public System::Windows::Forms::Form { private: System::Windows::Forms::ComboBox^ form_combobox; private: delegate String^ getItemDel();//<-- delegate … | |
Re: 1. int a[ ][ ] ={{2,3},{3,4},{4,5}}; i. It will create a 3*2 matrix and initialize it 1. 2. 1. [ [2][3] ] //<-- one way to think about it. 2. [ [3][4] ] //3 x 2 3. [ [4][5] ] |
The End.