1,296 Posted Topics
Re: [code=cplusplus] bool conjugated(const std::string& s1, const std::string& s2) { return s1.size() == s2.size() && (s1+ s1).find(s2) != std::string::npos; } [/code] ;) | |
Re: 1. It looks like a black cat in the dark room (from the user interface point of view). What's series #1, #2 etc? 2. You NEVER get [icode]pi1==counter[/icode]: you forgot that doubles are real number approximations. | |
Re: One of the most exciting process log (or use case scenario? ) I have ever seen... Thank you, waphon! | |
Re: Improvements? Try to process this (correct) line in C++ and see what happens: [code=cplusplus] ifstream file("//please/dont/strip.me"); [/code] ;) | |
Re: The working (or current) directory does not bear a relation to the starting executable module placement - that's the answer to OP question. | |
Re: 1. Use code tag with the language specifier: [noparse][code=cpluplus] source [/code][/noparse] 2. We can't help you (mor precisely, we can't verify your solution) without class Stack definition. However I see that your Copy member signature is wrong. You never modify passed by value parameter. If you want to copy from … | |
Re: As usually (on this forum ;)), you OP don't understand floating-point type data semantics. Floating-point numbers are [b]approximations[/b] of real numbers. For example, double(3.14) is NOT equal (exactly) to 3.14, double(0.1) is NOT equal to 1/10. Try this and see what happens: [code=cplusplus] double d = 0.0; for (int i … | |
Re: About this (bad) interface: 1. Bad copy constructor signature. Avoid non-const copy constructor argumen(s). Change to common: [code=cplusplus] Collector(const Collector&); [/code] 2. You shall overload an assignment operator or make it private (unmovable objects) for such classes with dynamic storage allocation; Add: [code=cplusplus] Collector& operator=(const Collector&); [/code] Otherwise you declare … | |
Re: About this thread title. Nobody can overload [icode][][][/icode] because [icode][][][/icode] is NOT an operator at all. This construct designates TWO [icode][][/icode] binary operators in succession. It's a senseless construct in C++. | |
Re: Problem 1: [code=c] int dueDate(int current_year, int current_month, int current_day, int days, int* pyear, int* pmon, int* pday) { int res = 0; struct tm t; t.tm_year = current_year - 1900; t.tm_mon = current_month - 1; t.tm_mday = current_day + days; t.tm_hour = t.tm_min = t.tm_sec = 0; t.tm_isdst = … | |
Re: Dear linked list traversal architect, don't waste a time, make a code ;) | |
Re: >this my code please i need help whether am right or not The best helper is your C compiler. Compile the code, run it - and see [i]whether you are right or not[/i]. Didn't you know that way? Are you sure that DaniWeb forum is a some kind of remote … | |
Re: fgets places '\n' char at the end of string. Overwrite it by zero byte (end of C-string) - that's all: [code=c] if (fgets(astr,sizeof astr,f)) { char* p = strchr(astr,'\n'); if (p) *p = '\0'; ... } else { /* eof or i/o error */ ... } [/code] | |
Re: What's a problem? [code=cplusplus] tot ^= !lngdata; [/code] | |
Re: Some notes: If points coordinates are not integers you never (or rarery) get exactly zero dot product. Furthemore, siddhant3s's solution (based on Pythagorean theorem) is faster than that (no need to calculate three expressions in the worst case). However siddhant3s's solution is incomplete too (does not take into account that … | |
Re: It's totally wrong approach: class std::vector object is not the same as its contents, [icode]sizeof(words)[/icode] does not bear a relation to the contained data size (print sizeof(words) value, it's constant). Never serialize/deserialize STL containers (include std::string) in a such manner. Probably the simplest way to serialize your struct strWord object … | |
Re: In most of (well known) C and C++ implementations rand is a very bad pseudo-random generator but it NEVER gets two equal numbers in succession (that's why it's a very bad...). I think it's impossible to get 264412, 26441... if you don't seed the generator with the same value just … | |
Re: You may achieve the same goal in C++ without cumbersome Word automation. Try to generate HTML report with a proper style sheet for media print. HTML files are simple text files so your report generator is an ordinar console application. No need in Word installation. Moreover, no need in Windows, … | |
Re: >I could not find any logical problems with the code... There is an obvious problem: this code does not copy zero byte of ct so the result string is not terminated (i.e. is not C-string). That's solution: [code=c] int ctsz = strlen(ct)+1; // don't use strlen() in for condition! for … | |
Re: Can't grok this mysterious code... Keep it simple: [code=cplusplus] while (it != v.end()) { if (++it != v.end() && ++it != v.end()) it = v.erase(it); } [/code] | |
Re: Try to convince JTC1/SC22/WG21 (The C++ Standards Committee) to incude class RubiksCube into the next (or better in the current) C++ Standard. After that you may expect to get the answer to simple and clear questions like that ;) See also: [url]http://en.wikipedia.org/wiki/Rubik's_cube#Algorithms[/url] | |
Re: Can you present the original specification of the "remove chars" stuff (not this wittingly incorrect implementation)? | |
Re: It's impossible to insert more or less bytes in the middle of the file. Of course, you can overwrite some bytes - that's all. As usually, file editors create new file and write new content to it, then rename or remove the old one and rename new file with the … | |
Re: [QUOTE=ShawnCplus;862548]You shouldn't have spaces in between the . and the poperty for one thing. [icode]axeman.att[/icode], not [icode]axeman. att[/icode]...[/QUOTE] Why?! [code=cplusplus] axeman // this . // is att // a legal = 40; // text [/code] May be I don't understand your statement? | |
Re: >how to sort alphanumeric file to find averages? I think that's your major problem: see the post title. No need in file sorting to get an average = sum_total / number_counter ;) The next (minor) problem: what's [i]alphanumeric file[/i]? What's input file contents? If there are numbers only in the … | |
Re: Remember: if statement works as ever ;) It's impossible that is_submenu(choice) is true if is_valid(choice) was true. The choice variable didn't changed between these two condition tests. Probably you fotgot to input a new value of choice... | |
Re: 1. Probably you want [icode]vector<A*>[/icode], not a senseless [icode]vector<*A>[/icode] ;) 2. >I have also created some objects of B and C, and stored it in the container... It's not a container of class A or B or what else objects. It's a container of [b]pointers[/b] to class A objects, feel … | |
Re: Yet another advice. I have used [b]Doxygen[/b] documentation system at initial stage of troubles with (as usually) undocumented third-party projects (from 50000 to 300000 lines in C and/or C++, hundreds of files). You may get a very visible web-oriented report with collaboration and inheritance diagrams, file dependencies, call trees, etc. … | |
Re: See, for example: [url]http://en.wikipedia.org/wiki/Virtual_inheritance[/url] So class className is a suitable player for "diamond" inheritance. | |
Re: Read my answer to another your thread on the same topic: [url]http://www.daniweb.com/forums/thread190507.html[/url] Are you sure that the more threads the better chance to get right answer? | |
Re: >technically this is C++ so you should use fstreams, really Moreover, you should use std::string instead this unsafe C-style input of a single word (see %s format specification) in 30-byte buffer (the right way to nowhere): [code=cplusplus] std::string filename; std::ifstream file; cout << "Enter filename: "; if (getline(cin,filename)) { file.open(filename.c_str()); … | |
Re: I have posted you at least two links to much more simpler than GNU MP bigint C++ libraries: [url]http://www.daniweb.com/forums/thread190103.html[/url] Why you ignore this fact? | |
Re: Take into account that [code] 123456 * 654321 * 80779853 == 6525384681074833728 [/code] but [icode]std::numeric_limits<long>::max()[/icode] is equal to 2147483647 on 32-bit processors (integer overflow is not detected). Try [icode]long long[/icode] type (it's supported by modern compilers now), its max value is 9223372036854775807. Otherwise try one of big int class libraries... | |
Re: >I need C help file database wich can be linked to my software ??? It's interesting: I have never seen such animals before... May be you want embedded database engine? That's it: [url]http://www.sqlite.org[/url] | |
Re: C-style casts are incorrect in that case: class B is_NOT_a C, A1 or A2. It's impossible to use this construct in the definition of parent of C: [code=cplusplus] class B { ... void foo() { C* p = dynamyc_cast<C*>(this); ... } ... }; [/code] Class B do not know its … | |
Re: Congratulations, all statements in your post are wrong. 1. No such animals as [i]abstract functions[/i] in C++. There are abstract classes... feel the difference. 2. It's enough to declare one member function [b]pure[/b] virtual or don't define inherited pure virtual function to make (to keep) the class into an abstract … | |
Re: May be it helps: [url]http://www.informit.com/articles/article.aspx?p=171014[/url] | |
![]() | Re: [code=cplusplus] /// fast int test (except possible overflow) bool isInt(const std::string& s) { static const size_t npos = std::string::npos; static const std::string digits("0123456789"); size_t pos = s.find_first_not_of(" \t"); bool res = pos != npos; if (res) { if (s[pos] == '+' || s[pos] == '-') pos++; res = (pos < … |
Re: >What is wrong with my sorting function? Probably it works. Try to test it ;) What's your problem? | |
Re: Use binary output (write member function) to save/get an array. It takes less than 1 second for ~1 million array elements (and probably ~1 milliseconds to populate this array as Salem said). | |
Re: [code=cplusplus] Log(LogFilename); [/code] You have wrote Log constructor in the expression-statement: create an object then discard it - redirect the stream then come back - i.e. do nothing ;). Try this (what desired): [code=cplusplus] Log anyVarName(LogFilename); [/code] | |
Re: Where is my crystall ball? No codes in your snippet. You may present excellent function prototype but where is this function body? It's interesting, can you help me right now: [i]I have some troubles with my car (well, I haven't), help me, please![/i] ;) | |
Re: Where are p1 and per1 vars class definitions? Why ios::app for input stream? "stop working" - what is it? Can you clearly describe your problem? | |
Re: You get uninitialized value of DateTime object. Try this: [code=cplusplus] DateTime t = DateTime::Now; [/code] Next (date and) time don't waste a time on forums: simply click on DateTime word then press F1 ;) | |
Re: [code=cplusplus] int linecnt; for (linecnt=0; getline(inData2,line); linecnt++) { } if (linecnt == 0) { // no lines report... return; // return value - return false, for example } [/code] Now [icode]if (!line)[/icode] is a wrong and senseless construct. No operator!() for std::string. You [b]have a line[/b] (may be empty) in … | |
Re: Use a simple and clear loop [code=cplusplus] while (getline(Data,line)) { ... } [/code] instead of clumsy and redundant [code=cplusplus] getline(Data,line); while (Data) { ... getline(Data,line); } [/code] | |
Re: If you want to follow C libary function memcmp specification (why not? ), take into account that: [quote]The sign of a nonzero value returned by the comparison functions memcmp, strcmp, and strncmp is determined by the sign of the difference between the values of the first pair of characters (both … | |
Re: Well, start from the beginning: what is an array declaration: [code=cplusplus] int inches[size]; // where size is a constant expression [/code] It's not the best method to learn language: waste a time in asking help on forums instead of read elementary textbook on a very basic language concept. ;) | |
Re: A stream object detects eof condition AFTER (but not before) read operation. Now let's suppose that pmd8.dat file is empty (yes, it's unusual but possible case): [code=cplusplus] ifstream numdata("pgm8.dat"); ... while (!numdata,eof()) { // eof() returns false now // Oops! Now you are trying to get NOTHING! ... numdata >> … | |
Re: I can't understand why you need additional comments to compiler messages in that case, Consider line #94: [code] String String::operator +(const String& str01, const String& str02) ... [/code] Where is this member function (incorrect) declaration in the class String definition? It's incorrect because of correct overloaded binary operator+ prototype is … |
The End.