353 Posted Topics
Re: > Because type char uses less memory than its int counterpart, I am curious why people don't prefer the former more often. Edward has come up with 4 reasons: [LIST=1] [*]int is the default integer type. [*]int is usually the same as the machine's word size. [*]Micro-optimizing storage is usually … | |
Re: You've commented out the definition of the copy constructor for Flight. | |
Re: The first thing you should do is break the problem down into simple steps, then outline the steps. From there you can translate those steps into C++ code, or a flowchart, or pseudo code, depending on how you learned about the process of programming. | |
Re: > Is it possible to not let the Form scroll down when running the code ? It's hard to tell what your problem is without seeing all of the code, but to mitigate the effect of the problem you can move the scroll bar position back to 0. It's kludgy, … | |
Re: > int top=1; That shouldn't even compile. You can't initialize class or struct fields except in a few specific cases, and this isn't one of those cases. > s.top=s.top+1; > s.values[s.top]=x; top is 1 to begin with, then you increment it before assigning the new value. That means you've lost … | |
Re: > I have a class privately encapsulated in another class. You can't access it except in the encapsulating class or friends of the encapsulating class. That's how private access works, and if you need to access the class outside of the encapsulating class or friends, then it shouldn't be private. | |
Re: What's the difference between the 2 and 3 versions? How are Point2 and Point3 different, for example? | |
Re: > Does anyone have some tips that I can use? C++ doesn't allow you to return an array. You can return a pointer to an array or a pointer to the first element of an array. Both of those are tricky to get right if the array is local to … | |
Re: What does setAngleList do? When you say [ICODE]Scan.setAngleList(Scan.MakeLinearGrid());[/ICODE] it passes a temporary object to the method. If setAngleList doesn't modify the object, you should make it a const reference anyway because that's both safer and more flexible in what you can pass. If setAngleList [I]does[/I] modify the object, you shouldn't … | |
Re: This is probably too advanced right now, but the STL has functions for a lot of these common tasks built in. You can fill a vector--instead of an array--with an unknown number of grades using copy and a back_inserter, print the vector using copy, and get the sum of a … | |
Re: As Edward said in PM, here's a hint: Use two arrays: one to store the numbers and one to store the numbers that have been counted. As you loop through the numbers, look for the current number in the counted array. If it's not there, add it and then count … | |
Re: The result of the sizeof operator will give you the size in bytes. The result type is size_t, but printf doesn't support printing size_t except in C99. You can get around that by casting the result to the largest unsigned integer type, unsigned long: [code] printf("Size of int (in bytes): … | |
Re: A stringstream is the easiest way to do what you want: [code] #include <iostream> #include <sstream> #include <string> int main() { const char *p = "0 1 9 12 78 0 1"; std::istringstream iss(p); int value; while (iss >> value) std::cout << value * 2 << '\n'; } [/code] | |
Re: If you want to make a completely unique copy of the data then you need to know the number of bytes as well as have a pointer to the data. Then you can allocate enough memory to the new pointer and manually copy the data: [code] unsigned char newData = … | |
Re: > it ony deletes when the number of the game is type not the name The number of the game matches the index in your vector. If you want the user to type the name of the game and delete it, you need to search for the name and return … | |
Re: [QUOTE=stephen84s;625084]In C++ [CODE]char FilePath[]="...[/CODE] is equivalent to :- [CODE]char *FilePath="..[/CODE] [/QUOTE] Those declarations are only equivalent as function parameters. The buggiest difference is that initializing the pointer points it to a read-only string literal while the array gets a writable copy of it. | |
Re: [QUOTE=mitrmkar;625205]Regarding code readability, you could save a lot vertical space by changing [code] cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; [/code] to [code] cout << "\n\n\n\n\n\n\n\n\n"; [/code][/QUOTE] Or use a … | |
Re: It's not really possible with standard C++ I/O. You need more control over keystrokes, and that means using non-standard functions. The most commonly known is getch. getch reads a scan code without echoing it to the screen: [code] #include <iostream> #include <string> #include <conio.h> int main() { std::string password; int … | |
Re: > so are you saying that its the name of the header file that matters in the header guard?? It doesn't matter what you use for a header guard name as long as it's unique. All that matters is that the symbol you define isn't defined anywhere else except in … | |
Re: Compilers are just translators that turn readable source code into binary machine code that the computer understands. When a language is created, somebody writes a compiler in a different language. Writing the second compiler in the new language is usually the trial run for a new language. > How is … | |
Re: > but i dont know any part of it..... The point of homework is for you to learn as you do it. You're not supposed to understand everything completely and be able to write it all without any effort. :icon_rolleyes: In fact, Edward would say that figuring things out on … | |
Re: Float code could mean a lot of things, can you be more specific? | |
Re: A cast to the native type works: [code] using namespace System; int main() { Int32^ Account = 100; Account = [COLOR="Green"](int)Account[/COLOR] + 100; Console::WriteLine(Account); } [/code] | |
Re: > if(date == CapeFile >> date && date == DurbsFile >> date) C++ lets you combine a lot of things, but this is a little too terse. ;) You need to read the file data separately and then compare it: [code] for(count = 0; count < Size; count++) { Date … | |
Re: As an aside, you use the C string and character functions, but forgot to include <cstring> and <cctype>. > cout<<"Winner!";//Ican't get to this When Edward runs the program, the problem shows up in the output for blank. You didn't null terminate the string, so strcmp is failing. That's easy to … | |
Re: > double free or corruption: 0x0937d008 With the copy constructor commented out, you have tons of alias pointers floating around. The destructor assumes that a copy constructor exists and allocates a unique pointer, but it doesn't. > Can someone check my code to see if there is anything wrong with … | |
Re: > I want to know whether there is any dfference between Heap and free Store in C++ Same thing, different terminology. > where can i get the "C++ standard docs"? The "official" document can be found at the ISO, NCTIS, or ANSI websites. IT costs money though, [url=http://webstore.ansi.org/RecordDetail.aspx?sku=INCITS%2fISO%2fIEC+14882-2003]$30[/url] to be … | |
Re: > But the following code is not working.c Did you include the code for compose2? It's not a standard STL function, but Edward would guess that you mean to use the one defined in Nicolai Josuttis' STL book: [code] #include <functional> /* class for the compose_f_gx_hx adapter */ template <class … | |
Re: The only real problem Edward sees is that you don't resize the dynamic array after the first call to AddFirst or AddLast. If you don't allocate the memory, you can't reliably write to it. Here is a simple implementation that carefully allocates more memory for each new item: [code] #include … | |
Re: > Let's say a=2, b=3; in for loop it will loop for 3 times rite? Right. If you know how many times the loop will loop, you can take the loop away and simplify the world: [code] a = 2; b = 3; calculation = 1; for(calc = 1; calc … | |
Re: > But I kept having errors such as Post the code, please. It looks like just a few syntax errors. | |
Re: Did you try [ICODE]myGrid->RowHeadersVisible = false;[/ICODE]? | |
Re: You can change column headers from the ColumnHeadersDefaultCellStyle property, but for it to work you have to set the EnableVisualStyles property to false. | |
Re: > why? I don't understand your question because it doesn't match what Edward knows about printf. The precision field of the %g format modifier uses significant digits because it supports both %f and %e formatting. When the %f formatting is used, as in this case, "significant digits" includes digits on … | |
Re: > vector <vector<string>> myvec; In the next C++ standard, yes. Right now the way the parsing rules work mean that >> is treated as a binary right shift instead of the closing character for a nested template. It's ugly, but you have to put a space between them for the … | |
Re: > I'm not sure what to put inside the indice boxes Ed would recommend the size of the array as it's required for an array reference. ;) [code] reset(int (&Board)[2][3]) [/code] The parentheses are also required to bind the reference operator to the array instead of to the type of … | |
Re: > You forgot to [ICODE]#include <numeric>[/ICODE] Edward isn't aware of an iota() function in the numeric header, or in the standard library at all. Is that new to C++ 0x? | |
Re: The type xmlDocPtr implies that it's a typedef for a pointer. Edward really doesn't like this practice since it causes exactly this problem: not using the right membership operator. Ed's guess is that instead of this: [code] doc.leerEntrada(); [/code] You should use this: [code] doc->leerEntrada(); [/code] p.s. Nevermind. Ed didn't … | |
Re: > This value I thought to use % of the caluclations but the operation can't be done with doubles(variable and constant). You can use the [URL="http://www.hmug.org/man/3/fmod.php"]fmod()[/URL] function to find the remainder of division for floating values. | |
Re: To do that in the console you can manually read characters and handle backspacing: [code] #include <iostream> #include <string> #include <conio.h> void GetInput(const std::string& prompt, std::string& field) { std::string temp = field; int ch; std::cout << prompt << ' ' << field; while ((ch = getch()) != '\r') { switch … | |
Re: > friend int Member::checkOut(); > friend int Member::checkIn(); Replace these two lines with this: [code] friend class Member; [/code] Edward doesn't have a solid reference on hand, but I don't think you can make a single non-static method be a friend. The friend has to be a non-member function or … | |
Re: Does [ICODE]strcat(variable1, variable2)[/ICODE] not do what you want? | |
Re: > ie a the numbers should not be repeated in my sequence,all numbers must be unique That's not a sequence, it's a set, and most random number generators don't guarantee uniqueness. You have to force that invariant yourself: [code] #include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <limits> #include … | |
Re: You can do this with streams and manipulators: [code] #include <iomanip> #include <iostream> int main() { std::cout << std::setw(4) << std::setfill('0') << 6 << '\n'; } [/code] A string stream can be used to write the result to a string instead of stdout: [code] #include <iomanip> #include <iostream> #include <sstream> … | |
Re: > use of undefined type 'Post' It means you're trying to use stuff from the Post class before you've fully defined the class itself. It's hard to say without seeing all of your code and how it's structured, but Ed would guess that you have a circular dependency and are … | |
Re: > My question is how it is possible to declare a number of elements as you do for native like this. OneVector(10) ? It isn't possible, but you can get close by using one of the overloads for the List<> class that expects an IEnumerable<T> object: [code] using namespace System; … | |
Re: > I need to get access to a pointer that is a private pointer in the parent class. The bad news is that there's no safe way to do that. Private members are private for a reason, are you sure you really need access to the pointer? Edward finds it … | |
Re: > the code below compiles but current and head are not initialized.. You can't initialize something that doesn't exist. When you say that a variable is extern, you're saying that it's defined and initialized elsewhere. If you don't define and initialize current or head elsewhere, you'll probably get a linker … | |
Re: A pointer to a function and a pointer to a method are different and have different syntax: [url]http://www.parashift.com/c++-faq-lite/pointers-to-members.html[/url] | |
Re: >Here's a recent example of the most horrific evils you can think of, but it is also the cleanest solution to the problem Clean is subjective. Edward would argue that instead of an infinite loop and goto, a flagged condition with a do loop is more intuitive and not any … |
The End.