353 Posted Topics

Member Avatar for scream2ice

C++ places hard limits on the size of the built in types. If you want something larger you need to use a library that supports big numbers, like [URL="http://gmplib.org/"]GMP[/URL].

Member Avatar for invisal
0
331
Member Avatar for conan19870619

[CODE] +1 // the last line is not terminated by NL [/CODE] But if the last line is terminated by NL, the count will be wrong. Sometimes it's better to be boring and conventional instead of clever and daring. ;) [code=cplusplus] #include <iostream> #include <sstream> #include <string> namespace EdRules { …

Member Avatar for Radical Edward
0
190
Member Avatar for mhil_joy
Member Avatar for phillipeharris

To make a class act like an array you can overload the [] operator to simulate the same kind of indexing: [code=cplusplus] class myQueue { public: myQueue(); myQueue(const myQueue & CCqueue); myQueue& operator =(const myQueue& rhs); ~myQueue(); void enqueue(const myQueue& Contributor); void dequeue(); bool IsEmpty(); bool IsFull(); int& operator[](int i) …

Member Avatar for phillipeharris
0
97
Member Avatar for Clockowl

break from the inner loop and then continue from the outer loop. If there's more to the body, you may need a flag or something similar: [code=c] while (condition) { int nextIteration = 0; while (condition) { if (condition) { nextIteration = 1; break; } } if (nextIteration) continue; ... …

Member Avatar for Clockowl
0
122
Member Avatar for Prm753

[QUOTE=Prm753]I am trying to optimize one of my applications by cutting down on the number of function calls I am making. I have decided to do this by reading definitions out of a file and using them as the argument for the function.[/QUOTE] You've probably already considered this, but file …

Member Avatar for ArkM
0
150
Member Avatar for daviddoria

How about storing those options in a singleton: [code=cplusplus] #include <iostream> #include <string> namespace EdRules { using namespace std; class GlobalOptions { public: string parallel; static GlobalOptions& Get() { static GlobalOptions options; return options; } private: GlobalOptions() {} GlobalOptions(const GlobalOptions&) {} GlobalOptions operator=(const GlobalOptions&) {} }; } void bar() { …

Member Avatar for Radical Edward
0
99
Member Avatar for disturbedfan

[CODE]cin>>name[/CODE] You're missing a semicolon to terminate the statement. [CODE]cout << [COLOR="Red"]end1[/COLOR]<< "Well Hello " << name.c_str()[/CODE] It's endl, with a lower case L, not end1 with the number 1. Edward would recommend using a font that makes that distinction. Ed uses Consolas. [CODE] cin>>number1; cin>>number2; [/CODE] number1 and number2 …

Member Avatar for Radical Edward
0
109
Member Avatar for Opsive

time_t is a black box, the right way to use it is through the inferface of functions that work with it. It could represent the time in increments of skittles strewn across the compiler developer's desk and still work perfectly when used the right way. ;) What are you trying …

Member Avatar for Radical Edward
0
2K
Member Avatar for BradenMurphy

What you want is an identifying downcast, where all you're doing is verifying that the dynamic type of the object matches the expected type for the operation. This can be done with C++'s dynamic_cast: [code=cplusplus] vector<Hardware*> hardware_stock; ... for(vector<Hardware*>::size_type i = 0; i != hardware_stock.size(); ++i) { Electric *p = …

Member Avatar for BradenMurphy
0
102
Member Avatar for symas

Not without storing the names as strings somewhere: [code=c] #include <stdio.h> typedef struct { int a; int b; } my_struct; const char * const my_struct_fields[] = { "a", "b" }; int main() { size_t n = sizeof my_struct_fields / sizeof my_struct_fields[0]; size_t i; for (i = 0; i < n; …

Member Avatar for Radical Edward
0
299
Member Avatar for sittas87

Edward is a strong believer in professional behavior. If the dispute is trivial, just let it go. If it's not trivial, avoid an immediate confrontation and file a complaint through the proper channels.

Member Avatar for steven woodman
0
217
Member Avatar for Nemoticchigga

Assuming you mean Windows Forms, a lot of controls are scrollable, like TextBox and Panel. You can also inherit the ScrollableControl class and write your own if none of the existing controls work out.

Member Avatar for Nemoticchigga
0
169
Member Avatar for nimloman

[code] for ( lineCounter = 1; lineCounter <= numLines; lineCounter++) cout << endl; setw(9); { [/code] The opening brace is in the wrong place. It should be right after the for loop stuff: [code] for ( lineCounter = 1; lineCounter <= numLines; lineCounter++) { cout << endl; setw(9); //{ [/code] …

Member Avatar for Radical Edward
0
211
Member Avatar for Dani

[QUOTE=Infarction;598804]The established community members should be the ones driving one's reputation. If you answer somebody's question, and it was a quick fix (but they obviously hadn't found the answer), that doesn't IMHO deserve any rep. It's when you do something that other members in the community acknowledge that you deserve …

Member Avatar for William Hemsworth
0
997
Member Avatar for get

Welcome to Daniweb! :) It's a great place to learn and have fun, but be ready to learn every way and not just the easy friendly way. Some of the coders around here can be kind of rough. And don't let it get you down; programming is hard, but it's …

Member Avatar for zandiago
0
34
Member Avatar for Cosa

Here's your loop with all of the extra stuff removed. The problem is easier to see here: [code] for(int a = 0; a < numrec -1; a++) { if(strcasecmp(cdstock[a].albumName, searchName) == 0 ) { ... return; } else { ... return; } } [/code] The loop never goes beyond the …

Member Avatar for Cosa
0
100
Member Avatar for nimloman

Edward is confused. The topic asks a different question than the example output suggests, and the example code doesn't solve the same problem as the example output suggests. :confused: Are you counting all characters, all non-blank characters, all upper case characters, or something else entirely? Anyway, since the problem seems …

Member Avatar for ArkM
0
113
Member Avatar for coveredinflies

What compiler do you use? Most compilers with an attached IDE have a place where you can put command line arguments. Visual C++ 2005 for example has it in the project properties under the debugging configuration.

Member Avatar for coveredinflies
0
107
Member Avatar for atish00

ele is never initialized. You should probably add a constructor that sets the data fields to something before working with them: [code=cplusplus] class array { private: int A[20]; int ele; public: array() { for (int i = 0; i < 20. ++i) A[i] = 0; ele = 0; } void …

Member Avatar for atish00
0
103
Member Avatar for ulquiorra

Why not use an ofstream to write to the file instead of fprintf and FILE pointers? If cout works just fprintf doesn't, it probably means that %s isn't the right specifier for n->data, but if you use an ofstream for the file output that's not a problem anymore because it …

Member Avatar for ulquiorra
0
303
Member Avatar for jonabie

>how to make an asterisk frame using for loop statement in C++ A frame for what? The top left and bottom are easy, and if the strings are all the same length, the right is easy too: [code=cplusplus] #include <iostream> #include <string> #include <vector> int main() { using namespace std; …

Member Avatar for jonabie
0
268
Member Avatar for loimarie

2x is multiplication; you can do it with [ICODE]2 * x[/ICODE]. The ^ operator exists in C, but not in the way that formulae use it. It means bitwise exclusive-OR instead of exponentiation. Turbo C supports the [ICODE]pow()[/ICODE] function though, so you can use that: [code=c] /* f(x)=2x^3+x^2 */ double …

Member Avatar for jephthah
0
525
Member Avatar for lil_panda

>still use strtol() Better to use stringstream: [code=cplusplus] #include <ios> #include <iostream> #include <sstream> int main() { using namespace std; istringstream is("ABCD"); unsigned int num; if (is >> hex >> num) cout << num << '\n'; } [/code] [code] [COLOR="red"]// Confusing name choice[/COLOR] char hex[]= "ABCD"; [/code] hex is also …

Member Avatar for Radical Edward
0
631
Member Avatar for Alex Edwards

The question isn't which you should buy, it's what order you should buy them in. :) Start with Effective C++, then More Effective C++, then go through the Exceptional C++ series: Exceptional C++, More Exceptional C++, Exceptional C++ Style. Ed would also recommend buying both the second and third edition …

Member Avatar for Alex Edwards
0
269
Member Avatar for Roy420

Edward doesn't see a problem converting between NRVec<double> and vector<double>, but because NRVec isn't designed to integrate with the STL, it's slightly harder than it should be. Converting a vector<double> to NRVec<double> can be done with the NRVec<> constructor like this: [code=cplusplus] std::vector<double> a; ... NRVec<double> b(&a[0], a.size()); [/code] Using …

Member Avatar for Radical Edward
0
135
Member Avatar for Scuppery

[QUOTE=Scuppery;659137] 2. Learn to work the toilet seat. You're a big girl. If it's up, put it down. We need it up, you need it down. You don't hear us complaining about you leaving it down. [/QUOTE] Last Edward checked, the problem was men leaving the seat down and pissing …

Member Avatar for abetageek
-2
275
Member Avatar for JackDurden

The ideal way to do this is to encapsulate the data into an object that defines a comparison operator. Then you can sort the objects instead of trying to sort parallel arrays: [code=cplusplus] #include <algorithm> #include <iostream> #include <stdexcept> #include <string> namespace EdRules { using namespace std; class Student { …

Member Avatar for Radical Edward
0
146
Member Avatar for ederX

>Let me ask, is it more conventional coding to use strings in c++ instead of char arrays, or vice versa? It's more conventional to use strings unless you have a good reason not to.

Member Avatar for Radical Edward
0
1K
Member Avatar for ++C LOVER
Member Avatar for peter_budo
0
149
Member Avatar for JaksLax

Did you change the definition of the constructor as well? [code=cplusplus] class Employee : public Person{ public: Employee(int eID = 000000000, string first = "N/A", string last = "N/A"); ... }; Employee::Employee(int eID, string first, string last) : Person(first, last) { setEmployeeID( eID ); } [/code]

Member Avatar for cikara21
0
112
Member Avatar for guest7

>What do the zeroes represent? Data? A line termination flag? It doesn't matter. The requirement is only to process the first number on each line. Since none of the other numbers on the line aren't being processed, it's a safe assumption that they won't show up in the output. >My …

Member Avatar for Radical Edward
0
238
Member Avatar for CoolGamer48

#import isn't available in C or C++, but if you want the same effect of it, some compilers implement a special #pragma for header files called once: [code] #pragma once // Header contents [/code] That's roughly equivalent to this: [code] #ifndef [I]magic name[/I] #define [I]magic name[/I] // Header contents #endif …

Member Avatar for Radical Edward
0
148
Member Avatar for Jishnu

> How should I calculate the similarity between any two words? The [URL="http://www.merriampark.com/ld.htm"]Levenshtein distance[/URL] algorithm is a good place to start.

Member Avatar for Jishnu
0
109
Member Avatar for lAmoebal
Member Avatar for sambafriends

When you want to print an address, you use the %p format modifier, and for extra safely cast the value to void*: [code] printf("%p\t%p\n", (void*)&i, (void*)&j); [/code]

Member Avatar for awi123
0
114
Member Avatar for Jennifer84

> the message is showing over and over again. There isn't anything in the code you posted that would cause that. Edward's guess is that the event is getting fired where you don't expect it, but it's hard to tell without more code. > I am trying to save the …

Member Avatar for Radical Edward
0
90
Member Avatar for Black Magic

> Anything is more fun than this ^.^ Everyone has a different idea of what's fun. For example, Edward is bored to tears when forced to write "proper window applications" in C++. ;) The nice thing about C++ is that we can all do our own thing and still have …

Member Avatar for Prabakar
0
125
Member Avatar for ff4930

> Can anyone suggest a way to start this? Do you know anything about recursive descent parsing? That would be Ed's first stop, because declarations can be nested as parameters, and handling of that comes with recursive descent. You can also search for source code of programs called "decl", they …

Member Avatar for Radical Edward
0
141
Member Avatar for Alex Edwards

> I've heard the virtual functions cause problems for performance and that the solution is always to use Templates/Generics. Virtual functions can cause performance problems, but so can templates. The only real solution is to measure where the bottleneck is and deal with it specifically. Vague guidelines like "use templates …

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

> Gotta love the SWAP macro too... Or better yet, the STL swap function from <algorithm>. ;)

Member Avatar for vijayan121
0
128
Member Avatar for QuantNeeds

> That means, if one omits the for-init statement the semicolon also disappears. That's not quite right, but Edward can easily see why you'd think that. Like most stuff in the standard, you have to look in several different places to get the whole picture. Specifically, the syntax for a …

Member Avatar for QuantNeeds
0
795
Member Avatar for QuantNeeds

pow is overloaded for multiple types, and all of them can be converted to from int. An easy way to fix the problem is to force the second argument to double: [code] int square = pow(integer,2.0); [/code]

Member Avatar for QuantNeeds
0
634
Member Avatar for Alex Edwards

Your use of pointers seems a little backwards, but the tree in your sample program is valid. Ed used a formatted display algorithm to see how it's structured. Here's something that is a bit more conventional in terms of how the pointers and values are handled: [code] #include <iostream> #include …

Member Avatar for Alex Edwards
0
115
Member Avatar for daviddoria

The binary * operator usually doesn't modify the state of the object anyway. It should always take a const reference: [code] geom_Vector3 operator * (double d, const geom_Vector3 &V); [/code]

Member Avatar for Radical Edward
0
108
Member Avatar for Alex Edwards

> If I use the [] operator and return a reference, is there any way to mark that indice when a value is assigned to it? It's your class, you can do anything you want internally. :) Edward would probably store a complex type with bookkeeping information: [code] #include <iostream> …

Member Avatar for Radical Edward
0
214
Member Avatar for TacklesMcCaw

> I was wondering more about the reasons a person would consider using their own namespace, what advantage they would get from it. Name conflicts are the most commonly stated reason for using namespaces, but Edward uses them for code organization too. Everything Ed uses for security might be in …

Member Avatar for TacklesMcCaw
0
154
Member Avatar for Alex Edwards

> Basically, how does one research allocation for different scenarios One learns the basics of dynamic memory and applies it in an ad hoc manner with every new scenario. Eventually you'll have seen scenarios before and the effort you put into doing it the first time will make subsequent times …

Member Avatar for Alex Edwards
0
75
Member Avatar for zoner7

> Can't I tell cout when it sees this number to display a space instead? Yes, just cast it as a char. > Will the compiler generate an error when I try to store a " " inside an int? Yes, but only because you need to specify a char …

Member Avatar for zoner7
0
92
Member Avatar for ff4930

Neither Matrix nor VNT need an explicit destructor, but the real problem is in the destructor for those two classes you try to delete objects that weren't returned by new: > delete mat; mat isn't a pointer, it's an object of type [ICODE]SA<SA<T> >[/ICODE]. The SA class handles its own …

Member Avatar for ff4930
0
79

The End.