353 Posted Topics

Member Avatar for zoner7

> 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 …

Member Avatar for Radical Edward
0
530
Member Avatar for 007tron
Member Avatar for 007tron
0
134
Member Avatar for sniper29

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.

Member Avatar for jephthah
0
405
Member Avatar for Jennifer84

> 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, …

Member Avatar for Jennifer84
0
437
Member Avatar for joshmo

> 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 …

Member Avatar for Sky Diploma
0
90
Member Avatar for 007tron

> 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.

Member Avatar for 007tron
0
119
Member Avatar for daviddoria

What's the difference between the 2 and 3 versions? How are Point2 and Point3 different, for example?

Member Avatar for Radical Edward
0
115
Member Avatar for zoner7

> 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 …

Member Avatar for Ancient Dragon
0
109
Member Avatar for daviddoria

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 …

Member Avatar for Duoas
0
1K
Member Avatar for AceChandra

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 …

Member Avatar for William Hemsworth
0
176
Member Avatar for azualin

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 …

Member Avatar for Radical Edward
0
65
Member Avatar for thirtan

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): …

Member Avatar for thirtan
0
92
Member Avatar for zourlas

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]

Member Avatar for zourlas
0
187
Member Avatar for amarhp

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 = …

Member Avatar for Radical Edward
0
84
Member Avatar for chickenlord500

> 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 …

Member Avatar for Radical Edward
0
85
Member Avatar for pwnz32

[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.

Member Avatar for pwnz32
0
3K
Member Avatar for cam9856

[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 …

Member Avatar for cam9856
0
103
Member Avatar for cbrules3033

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 …

Member Avatar for cbrules3033
0
108
Member Avatar for SwathiSangral

> 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 …

Member Avatar for Radical Edward
0
126
Member Avatar for zebanaqvi

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 …

Member Avatar for Ancient Dragon
0
62
Member Avatar for sniper29

> 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 …

Member Avatar for jephthah
0
492
Member Avatar for narendharg
Member Avatar for Aia
0
133
Member Avatar for mariaczi_pl

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]

Member Avatar for Ancient Dragon
0
240
Member Avatar for Traicey

> 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 …

Member Avatar for Radical Edward
0
126
Member Avatar for timdog345

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 …

Member Avatar for joshmo
0
144
Member Avatar for ff4930

> 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 …

Member Avatar for Radical Edward
0
807
Member Avatar for himsymcpp

> 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 …

Member Avatar for vijayan121
0
136
Member Avatar for ambarisha.kn

> 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 …

Member Avatar for vijayan121
0
89
Member Avatar for MAXPAYNE88

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 …

Member Avatar for MAXPAYNE88
0
101
Member Avatar for J-son

> 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 …

Member Avatar for J-son
0
104
Member Avatar for bookworm619

> But I kept having errors such as Post the code, please. It looks like just a few syntax errors.

Member Avatar for Radical Edward
0
144
Member Avatar for Jennifer84
Member Avatar for Jennifer84
0
107
Member Avatar for Jennifer84

You can change column headers from the ColumnHeadersDefaultCellStyle property, but for it to work you have to set the EnableVisualStyles property to false.

Member Avatar for Jennifer84
0
121
Member Avatar for wellibedamned

> 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 …

Member Avatar for wellibedamned
0
114
Member Avatar for faust_g

> 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 …

Member Avatar for Radical Edward
0
146
Member Avatar for zoner7

> 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 …

Member Avatar for Ancient Dragon
0
124
Member Avatar for ambarisha.kn

> 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?

Member Avatar for Radical Edward
0
1K
Member Avatar for fedderico10

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 …

Member Avatar for fedderico10
0
662
Member Avatar for kllera

> 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.

Member Avatar for Radical Edward
0
190
Member Avatar for viperwarp

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 …

Member Avatar for Nick Evan
0
112
Member Avatar for nirali35

> 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 …

Member Avatar for nirali35
0
559
Member Avatar for CodeBoy101
Member Avatar for kaos

> 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 …

Member Avatar for kaos
0
105
Member Avatar for savinki

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> …

Member Avatar for Radical Edward
0
102
Member Avatar for janicecbeginner

> 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 …

Member Avatar for VernonDozier
0
190
Member Avatar for Jennifer84

> 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; …

Member Avatar for Radical Edward
0
105
Member Avatar for msupstream

> 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 …

Member Avatar for msupstream
0
197
Member Avatar for joshmo

> 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 …

Member Avatar for joshmo
0
204
Member Avatar for zzmgd6

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]

Member Avatar for vijayan121
0
263
Member Avatar for phalaris_trip

>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 …

Member Avatar for Duoas
0
274

The End.