353 Posted Topics
Re: Edward's guess is that you get one star every 1,000 posts. That seems consistent, but Ed has been wrong too often in the past. ;) | |
Re: > As a result, I thought that any changes to the array would be carried over outside the function. That's different. Arrays decay into a pointer to the first element and that's why you can change the elements: [code] #include <iostream> void foo(int a[]) { for (int i = 0; … | |
Re: From what Edward has seen, you're using Windows Forms and not Win32. Without any of the bells and whistles of the standard message box, it's pretty simple to write your own message box dialog that closes after a set time. Here's a bare bones example: [code] #pragma once using namespace … | |
Re: Alternatively, you can make a class where the return values are fields and the object can be called like a function by overloading the () operator: [code] #include <iostream> #include <string> struct Name { std::string First; std::string Last; void operator()() { std::cin >> First >> Last; } }; int main() … | |
Re: The Columns property gives you access to individual column attributes: [code] dataGridView1->Columns[0]->Name = "Ed's Column"; [/code] | |
Re: > i finally came up with this, it's a result of my first idea of nulling... Clever solution! Ed likes it, and to be honest, the only way Ed could improve on it would be to clean up the code a bit, make it tighter, and add Edward's style: [code] … | |
Re: > for( int i = 0; i < checkedListBox1->Text->Length; i++) Edward doesn't understand how this is supposed to search the items. The Text property gives you the text of the currently selected item. Ed would expect something more like this: [code] for (int i = 0; i < checkedListBox1->Items->Count; ++i) … | |
Re: Edward learned it like this: [LIST=1] [*]Player picks a number between X and Y [*]Computer guesses half way between X and Y [*]Player says higher or lower [*]Computer sets X to the guessed number if player says higher, or Y to the guessed number of player says lower [*]Computer guesses … | |
Re: ++variable means that the variable is incremented by one and the new value is returned. variable++ means that the variable is incremented by one and the old value is returned: [code] #include <iostream> int main() { int variable = 0; std::cout << ++variable << '\n'; // Prints 1 std::cout << … | |
Re: > how do i make the array of authors bigger? If the size is going to be dynamic, you'll have a more pleasant time using vectors than arrays: [code] #include <string> #include <vector> struct library { std::vector<std::string> authors; }; [/code] Dynamically resizing arrays is tedious and error prone. | |
Re: What you're trying to do is concurrent processing. An easy way to do it is with .NET 2.0's [URL="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx"]BackgroundWorker[/URL] class to start a separate thread for the time intensive loop. | |
Re: What are you going to do with the values? Are you guaranteed that whitespace will separate the operators and operands? It could be really simple, or you might be better off writing a few classes that hold the raw equation data but still pass out extracted values. Depends on what … | |
Re: Edward prefers to pass data between forms using properties. Delegates work more with behavior than data, so they probably aren't a good match for what you want to do, which is something like this very incomplete example: [code] ref class Form1: Form { int _data; public: Form1() { _data = … | |
Re: > in a windowed project, i noticed my couts are not showed in the screen Unless the program attaches itself to a console for you or you attach to a console manually in your code, you're stuck with the usual suspects: redirect stdout to a file or use a file … | |
Re: > ok so i know all there is to know with text programming in c++. I doubt that. ;) Writing GUIs isn't the end all be all of C++ programming, and the lion's share of the work is done behind the interface. If you know all there is to know … | |
Re: C++/CLI handles boxing and unboxing implicitly. Either of these work just peachy: [code] using namespace System; #include <iostream> int main() { String^ s = "123"; int x = Convert::ToInt32(s); std::cout << x * x << '\n'; } [/code] [code] using namespace System; #include <iostream> int main() { String^ s = … | |
Re: Does your sprintf call look like this? [code] #include <stdio.h> int main(void) { int x = 123; char s[4]; /* Enough room for "123" +1 for null character */ sprintf(s, "%d", x); puts(s); return 0; } [/code] How exactly was it unsuccessful for you? | |
Re: To expand on Lerner's answer, you're probably reading strings like this: [code] #include <iostream> #include <string> int main() { std::string name; std::cout << "Name your character: "; if (std::cin >> name) std::cout << "Hello, " << name << '\n'; } [/code] When cin works with the >> operator, it reads … | |
Re: > This should do what i want correct? That's it. :) If you declare a pointer to BSNode<T>, that's all you have, a pointer. You can't reliably use that pointer until you set it to point to null or an address that reserves enough memory to hold an actual BSNode<T> … | |
Re: > Horse h1(Distance(p)); This is an evil bug. C++ isn't seeing that line as an object definition, it's seeing the line as a function declaration. h1 is a function that returns a Horse object and takes a Distance parameter called p. It looks like a parameter because C++ treats the … | |
Re: > What is a literal array? Edward's guess is that a literal array is supposed to be an initialization list: [code] int x[] = { 1, 2, 3, 4, 5 }; [/code] | |
Re: > Why do I need to 'return' a pointer? Probably because returning a full object is too expensive. Pointers are usually smaller than the objects they point to, so passing and returning pointers can be more streamlined. > The author of the code writes in FunctionTwo "return theCat;" Why did … | |
Re: Edward has two suggestions. First, you can use the std::pair template from the utility header and store both the item text and check state: [code] std::vector<std::pair<String^, CheckState^> > ItemInfo; for (int i = 0; i < CheckedListBox1->Items->Count; ++i) { String^ text = CheckedListBox1->GetItemText(CheckedListBox1->Items[i]); CheckState^ state = CheckedListBox1->GetItemCheckState(i); ItemInfo.push_back(std::make_pair(text, state)); } … | |
Re: The Items property gives you everything, and from there it's no trouble to get the checked state for each item. | |
Re: If the code is run from more than one event, you should refactor it into a method: [code] void button1_Click(Object^ sender, EventArgs^ e) { // Stuff for button 1 Button2Stuff(); } void button2_Click(Object^ sender, EventArgs^ e) { Button2Stuff(); } void Button2Stuff() { // Stuff for button 2 } [/code] You … | |
Re: You're printing the address of the pointer, not the address of the memory pointed to. Remove the address-of operator from your cout statement and you'll get the address of the memory that new gives you: [code] cout<<"This room is stored at: "<< room <<endl; [/code] | |
Re: > how we can access fun2() using deleted pointer. You can't. Even if it works once, you can't rely on it to work always. You're seeing what's called "undefined behavior", where your compiler doesn't have to follow any rules about what's supposed to happen. The compiler could do what you … | |
Re: The >> operator is type safe, it knows what type you want and doesn't allow any characters that don't fit the type. What Edward means is that 'N' and 'n' aren't legitimate characters in an int. :) When you type one of those, cin goes into an error state and … | |
Re: You can simplify your loop by reading input in the condition. That way you don't have to prime the variable with [ICODE]cin>>letter[/ICODE] before the loop: [code] while (cin.get(letter) && letter != SENTINEL) { if (isupper(letter)) cout << letter; } [/code] | |
Re: Edward needs more information. Can you post the actual code you're using instead of paraphrasing? It's easier to optimize code than guess about what your solution looks like. :) | |
Re: > if ( m_TickList->Count.CompareTo > 15) Edward gets an error here too. CompareTo isn't even being treated like a function. > I am not sure how to fix this.. ICollection doesn't have an overloaded indexing operator, but you can use the GetByIndex method of SortedList: [code] if (Convert::ToInt32(m_TickList->GetByIndex(Z)) > HighestHigh) … | |
Re: The STL list has a constructor that takes iterators. You can use that to initialize the list with the contents of your vector: [code] std::list<T> myList(vec.begin(), vec.end()); [/code] T is the same type as what vec holds. | |
Re: > It works because you assume the the character set is contiguous, and is basically US-ASCII Or Unicode, and Unicode is the future of character sets. Edward definitely recommends toupper, but when was the last time you worked on an IBM mainframe? ;) | |
Re: The hard part is working out how to get a random line from the file when you don't know how many lines there are. One way is to read the file once and count the lines, then use that count to pick a random number. A cooler way is a … | |
Re: C++ doesn't directly support a static class. Are you talking about a class that only has static members and doesn't have a public constructor? | |
Re: You can still use ofstream, but you have to overload the << operator for your struct: [code] struct gydytojas { int gydid, amzius, specialyb, telefonas, asmkod; String vardas[25]; String pavarde[35]; String adresas[50]; friend ostream& operator<<(ostream& os, const gydytojas& obj); }; ostream& operator<<(ostream& os, const gydytojas& obj) { // Print the … | |
Re: For a beginner's C++ book, Edward recommends [URL="http://www.amazon.com/Accelerated-Practical-Programming-Example-Depth/dp/020170353X"]Accelerated C++[/URL]. | |
Re: [code] #include <iostream> #include <iomanip> #include <string> #include <bitset> int main() { std::cout << "Enter a binary number: "; std::string bin; if (getline(std::cin, bin)) { std::bitset<32> bits(bin); std::cout << std::oct << bits.to_ulong() << '\n'; std::cout << std::hex << bits.to_ulong() << '\n'; } } [/code] | |
Re: It's hard to help if you don't ask a question. Do you have any code that's not working right or do you not understand parts of the problems? Or did you just want someone to do your homework for you? ;) | |
Re: The concepts are the same between Windows and Linux, but the details are different. You'll use different APIs and usually different libraries suited to the OS. There are portable libraries that work across multiple systems though, like Qt. Ed doesn't have much IDE experience on Linux, but Code::Blocks has a … | |
Re: gydytojas is a struct, but you use it like an object. The problem is the same as if you tried to say [ICODE]int.value = 5;[/ICODE], and the fix is to define a variable of gydytojas to work with. :) | |
Re: 1: [URL="http://www.microsoft.com/express/vc/"]Visual C++ 2008 Express Edition[/URL] is good and free. [URL="http://www.codeblocks.org/"]Code::Blocks[/URL] is good and free IDE that comes with MinGW for the compiler which is also good and free. 2: [URL="http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html"]Thinking in C++[/URL] is two full books of good stuff about C++. The first book is more beginner stuff and … | |
Re: > How to pass the input of a textbox in Form1 onto Form2? I guess it depends on how you open the forms. If Form2 is the main form and controls Form1, you can use a property to get the login name: [code] // Put this in Form1 property String^ … | |
Re: An if with more than one statement has to be wrapped in braces: [code] // This is OK! if (something) statement; // This is not OK! if (something) statement; statement; statement; // This is OK! if (something) { statement; statement; statement; } [/code] What's happening is the else part of … | |
Re: You should abstract your data into objects so that it's easier to make changes and the design is clearer. Right now you have three vectors of data that should be encapsulated in a student class: [code] class Student { std::string _firstName; std::string _lastName; int _score; friend std::ostream& operator<<(std::ostream& os, const … | |
Re: The problem is that you need to know how long the string is before you can allocate memory for it, and you need to input the string and store it somewhere before you can get the length... :confused: That's why the string class is so great, it does all of … | |
Re: You're trying to compare itemNo with a character '0100', don't forget that single quotes mean character and double quotes mean string. But itemNo is an int, so no matter what you type, you're not going to match it. The same goes if you take the single quotes away because 0100 … | |
Re: Ed never liked nested classes. They feel inelegant to me, especially when data access is much more important than class visibility and it's easy to restrict class visibility to a single file: [code] // Assume you don't want CColor or CBox // to be visible outside of this file namespace … | |
Re: An array of char cannot be converted to char unless it is an array of 1. The reason is that one cannot fit more than one char value into a single char variable. You can process each char individually though. To do that, use two nested loops, one for each … | |
Re: > I cannot compile programs in C++ done with previous versions (6.0) Visual C++ 6.0 allows both old style and new style iostream code. Your program might be including fstream.h instead of fstream, and you have to tell the compiler what namespace the name is in: [code] #include <fstream> // … |
The End.