1,296 Posted Topics

Member Avatar for Xellos_Moon

[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] ;)

Member Avatar for ArkM
0
91
Member Avatar for Akis2000

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.

Member Avatar for Akis2000
0
348
Member Avatar for waphon

One of the most exciting process log (or use case scenario? ) I have ever seen... Thank you, waphon!

Member Avatar for ArkM
0
171
Member Avatar for Sky Diploma

Improvements? Try to process this (correct) line in C++ and see what happens: [code=cplusplus] ifstream file("//please/dont/strip.me"); [/code] ;)

Member Avatar for tux4life
0
329
Member Avatar for ulisse0

The working (or current) directory does not bear a relation to the starting executable module placement - that's the answer to OP question.

Member Avatar for ArkM
0
506
Member Avatar for drunkenmonk

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 …

Member Avatar for drunkenmonk
0
3K
Member Avatar for Akis2000

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 …

Member Avatar for Akis2000
0
143
Member Avatar for timb89

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 …

Member Avatar for ArkM
0
87
Member Avatar for Talguy

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

Member Avatar for Talguy
0
108
Member Avatar for schaffino

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

Member Avatar for schaffino
0
109
Member Avatar for BlackStar
Member Avatar for BlackStar
0
505
Member Avatar for richardcyper

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

Member Avatar for ArkM
0
134
Member Avatar for CoolAtt

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]

Member Avatar for Aia
0
5K
Member Avatar for kiske
Member Avatar for SallyJ

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 …

Member Avatar for ArkM
0
2K
Member Avatar for Playtner

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 …

Member Avatar for Playtner
0
93
Member Avatar for arpeggio54

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 …

Member Avatar for Narue
0
88
Member Avatar for norulez43

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

Member Avatar for ArkM
0
161
Member Avatar for kaku_lala

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

Member Avatar for ArkM
0
133
Member Avatar for karlad

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]

Member Avatar for ArkM
0
85
Member Avatar for anoop sharma

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]

Member Avatar for Lerner
0
120
Member Avatar for Toila

Can you present the original specification of the "remove chars" stuff (not this wittingly incorrect implementation)?

Member Avatar for WaltP
0
2K
Member Avatar for tgsoon2002

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 …

Member Avatar for tgsoon2002
0
265
Member Avatar for kiwihaha

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

Member Avatar for kiwihaha
0
153
Member Avatar for emanmae

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

Member Avatar for emanmae
0
185
Member Avatar for BlackStar

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

Member Avatar for BlackStar
0
229
Member Avatar for ganmo

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 …

Member Avatar for ganmo
0
114
Member Avatar for serkan sendur

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

Member Avatar for serkan sendur
0
90
Member Avatar for serkan sendur

See, for example: [url]http://en.wikipedia.org/wiki/Virtual_inheritance[/url] So class className is a suitable player for "diamond" inheritance.

Member Avatar for serkan sendur
0
137
Member Avatar for tgsoon2002

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?

Member Avatar for ArkM
0
80
Member Avatar for jrynik

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

Member Avatar for jrynik
0
147
Member Avatar for henryxxll

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?

Member Avatar for Peter_APIIT
0
222
Member Avatar for Peter_APIIT

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

Member Avatar for Peter_APIIT
0
461
Member Avatar for ni30rocks

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

Member Avatar for ArkM
0
85
Member Avatar for axfv

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 …

Member Avatar for ArkM
0
179
Member Avatar for ganmo

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 …

Member Avatar for ArkM
0
103
Member Avatar for gr8ash
Member Avatar for ArkM
0
228
Member Avatar for nicolap

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

Member Avatar for vmanes
0
208
Member Avatar for musique

>What is wrong with my sorting function? Probably it works. Try to test it ;) What's your problem?

Member Avatar for musique
0
255
Member Avatar for NathanOliver

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

Member Avatar for NathanOliver
0
107
Member Avatar for daviddoria

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

Member Avatar for ArkM
0
178
Member Avatar for olejl

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] ;)

Member Avatar for ArkM
0
622
Member Avatar for saadjaved14

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?

Member Avatar for ArkM
0
107
Member Avatar for Lukezzz

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

Member Avatar for ArkM
0
103
Member Avatar for Peyton

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

Member Avatar for William Hemsworth
0
147
Member Avatar for hurbano

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]

Member Avatar for ArkM
0
88
Member Avatar for kaku_lala

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 …

Member Avatar for ArkM
0
351
Member Avatar for songweaver

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

Member Avatar for siddhant3s
0
135
Member Avatar for cbreeze

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

Member Avatar for siddhant3s
0
97
Member Avatar for losh177

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 …

Member Avatar for losh177
0
270

The End.