1,296 Posted Topics
Re: [code=c++] inline char* Min(char* a, char* b, char* c) { return strcmp(a,b) < 0 ? strcmp(a,c) < 0? a: c : strcmp(b,c) < 0? b: c; } [/code] ;) | |
Re: Alas, you can't get desired effects with list<Vehicle>. The point is that std::list<Vehicle> container might save only Vehicle (base) part of an object, however you want to save not an abstract Vehicle but a Car object, a Bus object and so on. That's why virtual functions and abstract classes were … | |
Re: [QUOTE=dougy83;746835]assuming str is of type 'string', str[i] is of type 'char'. chars will be considered negative whenever the top bit is set. It's not an issue if you are bitwise ORing, as you will get the correct result. If it annoys you, feel free to cast to unsigned char, as … | |
Re: [QUOTE=rumencho;747039]Hi all. When I create simple console application with Visual Studio C++ ,and I run it, my program shows on full screen, How to adjust my .exe files to show on single console window?[/QUOTE] It's not .exe file issue. Change your windows installation command shell window properties. Look at [url]http://commandwindows.com/configure.htm[/url]. … | |
Re: 1. You never compare [icode] Name : Rose[/icode] with fgets'ed line because fgets appends '\n' to a line, so it looks like [icode] Name : Rose\n[/icode]. Solution: use strstr instead strcmp: [code=c] if (strstr(T,B[e])) { /* T found */ ... } ... [/code] 2. You are trying to copy FUTURE … | |
Re: 1. The make5 is not a method, it's an ordinar function. Strictly speaking, no "method" term in C++. It's an informal alias for non-static member function. 2. Semantically a reference in C++ is another name of an object allocated in the memory (not only on the stack - moreover, no … | |
Re: 1. Try to profile subset generator without any printing. There are ~1 million subsets (2^20) for N==20. To print 1 million lines... The program PRINTS all the time. 2. NextSubset code is obviously wrong: [icode]while(!Bitmask[i]&&i>=0)[/icode] refers to Bitmask[-1] at the last loop. Present all class Subset definition. | |
Re: I can't compile your code with VC++ 9 because it's an example of ill-formed C++ program. If you define (wrong) copy constructor with [icode]Vector<F>&[/icode] argument, it's impossible to initialize Vector<float> variable with Vector<double> initializator. The only possible way to do that is: 1. Convert Vector<double> object to temporary Vector<float> object. … | |
Re: 911: [url]http://www.daniweb.com/forums/announcement8-2.html[/url] Sample code needed? Google is your friend!.. | |
Re: [QUOTE=JCasso;744426]Hi, I am programming a pos terminal by using C Programming language. I cannot use strtod() or atof (since it just calls strtod in it). Any advices on converting string to double without using these functions?[/QUOTE] Well, use sscanf. I think it's an incorrect question. Why pos terminal control program … | |
Re: 1. You can't declare a vector of references in C++ (it's the other story why). Fortunately, I see a vector of POINTERS in you snippet. Feel the difference ;) 2. Why pointers in that case? Better define [icode]std::vector<SalariedEmployee>[/icode]. Take on trust: it's much more better for you ;) 3. What's … | |
Re: Yes, you are still fairly new to C++. The myp2 variable is a pointer to [icode]mypair<int>[/icode] so must be [code=cplusplus] cout << myp2->getVal() << endl; // pointer->member // or cout << (*myp2).getVal() << endl; [/code] The last code means: dereference pointer (get an object) then call member function for this … | |
Re: The template generation does not pay attention to executable statements in the template definition. The [icode]if (n > 0)[/icode] does not prevent recursive template bootstapping for [icode]GetNRands<0>, GetNRands<-1>[/icode] and so on. It's pity that VC++ can't detect this "instantiate forever" recursion. To break this recursion you may define this template … | |
Re: Reread the get member function specification more carefully. If [icode]cin.get(b,2)[/icode] can't obtain the next char from the cin, it sets failbit for cin. When the cin stream is in failed state, no more operations performed until you clear the cin state (by cin.clear(), for example). Now cin.ignore and cin>>... ignored … | |
Re: Don't waste a time for this nonsense. Download some ready-to-use keyboard sniffer and enjoy... For example: [url]http://3d2f.com/tags/keyboard/sniffer/[/url] | |
Re: [QUOTE=minas1;744460][B]result[/B] is a local variable, which is destroyed when the functions ends. So a garbage value is destroyed. The best solution is to do what is said by the poster above. If you need to work with pointers you can do this: [code=C++] double* treble(double data) { double result = … | |
Re: Some additions. I think a radix sort is not a suitable method to sort array of structures with sort key fields. You need a lots of additional memory and unnatural code modifications. Probably the simplest way to adopt common sort codes (usually published with int array parameter) for structures sorting … | |
Re: Have you ever seen the compiler message? It's AdjacencyMatrix constructor was not defined! | |
Re: I see a very bad class design and implementation but no any compile-time errors ;)... | |
Re: It's not C++ language question. It's a question about YOUR compiler and linker. Read the compiler reference guide carefully, look at module map, try and see what happens - and so on... | |
Re: 1. Directly? You can't. But you can read word by word: [code=c] char word[32]; ... while (fscanf(f,"%31s",word) == 1) printf(">%c<\n",word[0]); /* that's the 1st char */ [/code] 2. You can't. Read line by line with fgets (or char by char with fgetc) then select ABCs explicitly. | |
Re: Totally unsafe: no null pointers check up at all. Strange operator= semantics. Right (common) operator= signature: [code=cplusplus] String& String::operator=(const String&); [/code] Try so natural p = q = s with your semantics ;) No useful string class methods (find, substr, individuall chars accessors etc). No operator <() - impossible to … | |
Re: Well, and what's your problem? May be better start from two wonderful ballades on this forum rules?.. [url]http://www.daniweb.com/forums/thread78223.html[/url] [url]http://www.daniweb.com/forums/announcement118-2.html[/url] | |
Re: Are you sure that you really understand the difference between "declare" and "define" in C++? I think jencas was right and you don't DEFINE that constructor. | |
Re: Keep it simpler, it's C++ now and here: ;) [code=cplusplus] #include <ctime> #include <cstdlib> #include <algorithm> ... srand((unsigned)time(0)); random_shuffle(deck,deck+52); // All done ;) [/code] | |
Re: Qbasic is not a general purpose platform-independent language, it's a concrete implementation of Basic language dialect. No keyboard notion per se in the C++ language. There are lots of keyboard access functions and libraries in C++ implementations. What's your C++ compiler? | |
Re: May be better stop this farce with rainbow coloured messages? It seems the (semi)professional forum is an area of communications but not a self-expresson... Have you ever seen the strtok C standard library function? | |
Re: Read about: - pointers to member functions: [url]http://www.gidforums.com/t-18332.html[/url] - pointer to data members: [url]http://www.icce.rug.nl/documents/cplusplus/cplusplus15.html#l219[/url] | |
Re: As far as I know you must use <iostream> and <fstream> headers and namespace std with Open Watcom C++ STL (incomplete) implementation (OWSTL) now. The old good WATCOM is a rather specific compiler. It seems the best place to get answers about OW peculiarities is OW community wiki and forum. … | |
Re: Nobody knows what order relation for matrix are you using. And you? ;) | |
Re: Have a look at the primary source: [url]http://www.keil.com/[/url] Of course, all Keil software tools are not freeware (one of the Product page headers: "Why Buy Tools From Keil?"). There are evaluation versions... Of course, it's the case where "Google is your friend", not DaniWeb... | |
Re: Please, don't use this awkward combination of words as "Pointer Functions". No such beasts as "pointer functions" in C and C++. There are "pointer to function" types in both languages, there are correspondent values and variables. A pointer to function is a kind of POINTERS, not a kind of FUNCTIONS. … | |
Re: Is it so hard job to correct obvious errors: you get compiler messages on wrong function arguments: fread and fwrite want POINTERS to target/source data areas (&d - not d, &b - not b))! Use code tag properly: [noparse][code=c] source [/code][/noparse] Never use dangerous gets function: it does not check … | |
Re: The ofstream sorted is local in the recursive member function display so you are trying to open file stream on every function call and close it by the sorted variable destructor on every return from display. Obviously, it's absolutely wrong and senseless effect. There are two possible solutions. You may … | |
Re: As far as I know there is [code=c] int xmlStrEqual(const xmlChar * str1, const xmlChar * str2) [/code] function in xmlstring module (and other xmlChar string handling functions). For example, you can convert xml-string to ordinar C-string then use atol to get integer value of attribute - and so on... … | |
Re: [url]http://www.edcc.edu/faculty/paul.bladek/Cmpsc142/matmult.htm[/url] ;) | |
Re: In other words you want to cheat your teacher (and yourself)... | |
Re: Sort chars? What for?!.. Can you explain what do you want to do with a file contents? | |
Re: Not only destructor: d_addatbeg is wrong too (see empty list case)... Please, use code tag correctly: [noparse][code=cplusplus] source [/code][/noparse] | |
Re: Better use [code=cplusplus] std::ifstream file(...); std::string line; ... while (getline(file,line)) { ... } if (file.fail()) { // i/o error occured ... } [/code] | |
Re: Never, ever trust in database client program supplied "unique numbers". A well-designed database must have properly defined unique counter fields in its tables and/or correspondent database procedures/triggers. Let's forget home-made x-"databases" of 80-th ;) | |
Re: You must detect bad input condition then handle it. If possible, make recovery. For example: [code=cplusplus] int x; cout << "Type integer: "; if (cin >> x) { cout << "Thank you..." << endl; } else if (cin.eof()) { // end of stream cout << "cin closed." << endl; } … | |
Re: 1. If no majorIn member in a structure, why you wrote senseless and invalid expression [icode]student[i]majorIn[/icode]? It's simple majorIn argument! 2. What for you wrote the 1st if statement? You don't initialize i at that moment but refer to [icode]student[i][/icode]... 3. Why so strange form [icode]for(i=0;i<=n-1;i++)[/icode]? Keep it simpler: [icode]for … | |
Re: It looks like an exam or test question ;) Well, it does not matter what's use function returned value: you forgot to initialize your c object ;)... Look at [url]http://www.daniweb.com/forums/announcement8-2.html[/url] | |
Re: [QUOTE=valchid;741719]and my tutor did say i can use gets or fgets so i dont know why he said it [/QUOTE] May be he is an inclined to sadism person. If so and if you are a latent masochist then use gets... ;) | |
Re: You wrote a bunch of C-style unsafe functions instead of a good C++ class List with comfortable and safe interface. Look at the class std::list as a model. Now these templates look like a steam-engine with microcontrolled whistle... | |
Re: You declare these member functions but forgot to define them. Probably, you define functions with such names without class name prefix, for example: [code=cplusplus] double GetRandomNumber() // Ordinar function { // does not bear a relation to the class ... } // You need double RandomVariableGenerator::GetRandomNumber() { ... } [/code] … | |
Re: 1. Use code tags correctly: [noparse][code=c] source [/code][/noparse] 2. It's not a declaration only (with extern) for global variable: it's a very strange definition (with enormous macros currentpacketbeingsampled? or with macros xdata? ): [code=c] char xdata currentpacketbeingsampled; [/code] Never add definitions (except classes and templates in C++) in header files. … | |
Re: Suppose one fine day (in year 1990, for example) the C++ Standard defines native binary data representations. Do you want 16-bit int now? How many long long longs are you ready to add in the future? An experienced and far-sighted software architect never relies on external data binary interfaces. There … | |
Re: [QUOTE=MylesDBaker;741808]Okay I figured out the default constructor. Now I need to create a function named "playerChoice" which changes the stored array value into whatever the player's space that is chosen and replaces it with an 'X' or 'O' and then calls a function to print out the current board status.[/QUOTE] … |
The End.