1,296 Posted Topics
Re: 1. You forgot that strcat works with c-strings i.e. char arrays with null byte at the end of contents: [code=c++] void express::parse(){ int i=0,x=0; char ch; // it's a single char, not char array while(i<len) { if (ch >= '0' && ch <= '9') { char* a; float f; int … | |
Re: Please, read your C++ book again (at least how to declare class variables and access its members). It seems all you know about C++ at the moment: // comments and operator << ;) Probably you can't understand the answer to your question now ([icode]age.("name") = age;[/icode] - it's cool! )... | |
Re: >But I don't understand how to sort the information in alphabetic order. Do you know any sorting algorithm? If not, come here: [url]http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx[/url] >And also the information which is written in information.txt is not neat. ??? | |
Re: The inner class does not have special access rights to outer class members, it's not a member of outer class (common misunderstanding of novices). The only effect is that inner class name scope is bounded by outer class. It's the same as ordinar (outside another class definition) class declaration in … | |
Re: It's not a class called, you call a member function for an object of another class. So if you can declare a variable of the class (as a member, for example) then you can call member functions of this variable class. Now let's remember: you must declare an entity before … | |
Re: [QUOTE=Manutebecker;760540]I must say I always love a program where I can use #include<vector> vectors are like the peanut butter to my chocolate![/QUOTE] Well, start all your modules from [code=c++] #include <vector> using std::vector; [/code] Who knows what may happen below ;)... | |
Re: 1. Please, USE code tag for your snippets properly: [code=c] your source texts [/code] 2. You don't understand operator sizeof functionality. See what happens in your (incorrect) memory allocation: glblclrtab= (char *)malloc(sizeof(3*tmp)); The malloc functions allocates `sizeof(3*tmp)` bytes. The C Standard: >The sizeof operator yields the size (in bytes) of … | |
Re: Obviously, the presented output was printed by another (version of) program (no member names in this snippet printf). Of course, VC++ 6.0 is too old compiler but I have worked with it many years and never have troubles with printf... Try to replace printf to cout << and see what … | |
Re: Let's start from this forum announcement: [url]http://www.daniweb.com/forums/announcement8-2.html[/url] I rather like this non-functional specification: [quote]please try to make it as simple as you can[/quote] Did you know the most valued principle of a good programming style and design: [b]Keep it simple, stupid[/b]? If so you have a good chance to become … | |
Re: Alas, [b]long long int[/b] is not a standard type in C++ at the moment. Moreover, the C++ (and C) standard garantees that long number type is not less that ordinar type - that's all (for example, [icode]sizeof(long long int) >= sizeof(long int)[/icode], but not [icode]sizeof(long long) > sizeof(long)[/icode]). Therefore it … | |
Re: 1. You may assign any type object pointer to a void* pointer variable without explicit conversion - no need in reinterpret_cast: [code=c++] void* pvoid[3]; pvoid[0] = &mc1; // or what else [/code] 2. It's possible but what for? All three variables mc1, mc2, mc3 have absolutely different types. Can you … | |
Re: 1. There are lots of fixed decimal/currency class libraries for C and C++: search Google. 2. What's a problem? Calculate all values in cents (use double type, don't forget floor and ceil library functions, Banker rounding method etc). Some year ago I have wrote ~100000 LOC of financial codes with … | |
Re: >first i copy an object byte by byte to a memory location It's one of the most dangerous operations (in general case illegal and erroneous), as usually symptom of a very bad code design. The only valid conversion void* to type* value is: the void* pointer value was obtained previously … | |
Re: Look at the sentence: [b]Well,find me[/b]. Are you sure that whitespaces only are valid word separators? | |
Re: [QUOTE=shaikh_mshariq;762983]I need to write a small application which can be used to store html from any web server. I have written some code that is able to fetch HTML page along with header. I need to know is there any way to distinguish these headers from actual html content. Can … | |
Re: I don't understand why you consider these three methods equally matched. The 1st method only builds the desired multimap. I think the std::multimap native interface is not suitable for most of applications (too cumbersome and unclear), so you need your own problem-oriented multimap wrapper class. You may initialize static multimap … | |
Re: [QUOTE=crioto;762386]For example, i have char variable = "This is a simple text"; and i need to put word "Very" between "a" and "simple" How to do it using standart C library?[/QUOTE] Use strstr library function to search "Very" in the string. If it's found make a room at this point … | |
Re: >I am trying to solve an easy problem (no doubt) - reading data from a tab delimited file and inserting it into a 2D array. Well, try to solve THIS problem: you have 4x5 integers in the text file and you need to read them into 2D INTEGER array, not … | |
Re: Think: a console program does not know what device receives stdout/cout output! Suppose you have prog.exe. See what happens when prog.exe started: 1. >prog -- ok, printf prints in console window 2. >prog >output.txt -- printf writes in file output.txt 3. >prog >nul -- printf "prints" nowhere (nul device - … | |
Re: Despite of this barbaric by value queue parameter and absolutely unnecessary copying to the local temp variable, it's a correct code. It works if the queue was initialized properly. Present outputQueue call context... | |
Re: And don't forget to terminate the last token when break the loop... | |
Re: [url]http://www.exforsys.com/tutorials/c-plus-plus/how-to-access-class-members.html[/url] | |
Re: Didn't you see that you show TWO open file dialog windows? You close the 1st dialog and immediately show the 2nd one in if expression... What for the 1st line of your snippet? Please, next time use code tag properly: [noparse][code=c++] text [/code][/noparse] | |
Re: [QUOTE=Ragupathiyuva;759961] Can anybody explain about int main(int argc,char* argv[]) [/QUOTE] Google search "main C argc argv tutorial"... Instant replay: lots of links RIGHT NOW... For example: [url]http://www.phon.ucl.ac.uk/courses/spsci/abc/lesson11.htm[/url] [url]http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html[/url] [url]http://www.dgp.toronto.edu/~ajr/209/notes/argv.html[/url] and so on... | |
Re: [code=c++] union BinCard{ uint64 Hand; // uint64 is an unsigned 64 bit int (use a typedef) SuitGrp SG;}; [/code] How about this solution portability? There are lots of compilers without 64-bit integer types ;)... | |
Re: It's unclear where global array definitions were placed. Probably, these [icode]#ifndef...char[][]={}...#endif[/icode] chain was placed twice. Place extern declarations only fragment in separated .h file, include it in .c modules where external arrays access needed. External arrays definitions (declarations with initialization) must be placed in one and only one source file … | |
Re: Have a look at the C++ creator's pages: [url]http://www.research.att.com/~bs/C++0xFAQ.html[/url] | |
Re: Alas, it's wrong solution because [icode]sizeof(T[])/sizeof(T)[/icode] does not bear a relation to an array size: it's the same as [icode]sizeof(T*)/sizeof(T)[/icode]. Remember: it's impossible to get an array size from [icode]type name[][/icode] declaration. Look at: [code=c++] template <typename T> class Sequence { public: Sequence() {} Sequence(const T a[], size_t n): terms(a,a+n) … | |
Re: Please, don't worry about that sacramental [b]third call[/b]! If strtok can't find third slash it returns the pointer to the start of year field (or what else after the second slash), but [b]the next[/b] call returns NULL. In other words, strtok returns NULL only when all c-string was scanned. For … | |
Re: Define your own manipulators, make a code simpler: [url]http://www.java2s.com/Tutorial/Cpp/0100__Development/Createanoutputmanipulator.htm[/url] ;) | |
Re: Visual C++ 9.0 compiler resolves this situation. Obvious workaround with your compiler: define explicitly default RMStore constructor (an all others): [code=c++] class RMStore { public: // Place public part at the beginning RMStore():status(false){} // You forgot initialize status member explicit RMStore(const char* pcmd): command(p?p:""),status(false) {} explicit RMStore(const std::string& cmd): command(cmd),status(false) … | |
Re: Well, class System HAS a vector of Schools. In other words, every System object contains a set of Schools. But class School IS a kind of System (by inheritance). So every School has a set of Schools?!.. Hmm... | |
Re: Well, it's too narrow and a little obscure code ;) I agree with previous posts. >can it be more efficent? What's your effectiveness criteria? [code=c++] bool Palindrome(const char* p) { if (!p) return false; if (!*p)return true; const char* pend = p; while (pend[1]) ++pend; while (p < pend && … | |
Re: The C++ Standard (16.2): [quote]2 A preprocessing directive of the form # include <h-char-sequence> new-line searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. … | |
Re: [QUOTE=karang;759744]if I have a variable called text of type char* then What should I write in VC++ so that it assigns emdash value in the variable text[/QUOTE] 1. The emdash character has value '\x97' in most of Windows single-byte code pages (it's equal to -105 if char type is signed … | |
Re: [QUOTE=Manutebecker;750641]I've been reading up on templates and they just seem like so much hastle for so little reward. I can't find anyway to effectively use it over vectors. I am just having a lot of trouble learning them because the concept seems so weird.[/QUOTE] Google "C++ templates tutorial" Lots of … | |
Re: [QUOTE=lulusweety;759119]Can you tell me which compiler(version) is suitable for doing exception handling?[/QUOTE] Have you ever read Ancient Dragon's post? Use Code::Blocks IDE with MinGW compiler (the same as frozen Dev-C++ IDE used): [url]http://www.codeblocks.org/[/url] | |
Re: [QUOTE=rkumaram;759124]... when we called constructor , it allocate memory for the object . right . [/QUOTE] A constructor does not allocate memory for the object. It does not know how to do that. Think about: [code=c++] class C { public: C(); C operator+(const C&); } ... C c; // static … | |
Re: 1. Use code tags: [noparse][code=c++] your code [/code][/noparse] 2. You don't understand a role of "stdafx.h" header in VC++. Place all system header includes in stdafx.h, not in your cpp modules: [code=c++] stdafx.h: ... #include <iostream> #include <fstream> #include <string> // TODO: reference additional headers your program requires here yourcppfile.cpp: … | |
Re: It works but too slowly (over two billions unnecessary loops) ;) Break the loop when you know that it's not a prime (and try to optimize code because it's a brutal force slow algorithm): [code=c++] ... // positive root_value only... double c = 2.0; bool prime = true; root_value = … | |
Re: It's a good time to remember header files. Place the structure definition in .h file then include it in both main.c and file2.c. Now you have common structure (and other types) definition source. A compiler knows nothing about main.c contents when processes file2.c. | |
Re: [QUOTE=Luckychap;758462]You cannot declare array with a variable size.[/QUOTE]It's true but [icode]new float[arrayLength][/icode] construct is not an array declaration: operator new creates anonymous array object, a new argument (number of elements) is an arbitrary arithmetical type expression. | |
Re: [QUOTE=Narue;757781]...though it's usually a better idea to design your class so as to not need a default value.[/QUOTE] It's not so easily to design an intrusive container class for elements without default constructor (no underlying arrays, for example). | |
Re: 1. No loops, no (run-time ;) ) recursion: [code=c++] template <int n> struct Hello: public Hello<n-1> { Hello() { std::cout << "Hello, world!\n"; } }; template <> struct Hello<0> {}; int main() { Hello<100> woodpecker; return 0; } [/code] | |
Re: 1. You have made a very bad style functional decomposition. Why an array is global? Define all processing functions with processed array and array size parameters. Never burden your functions with redundant external dependencies. You CreateArray function does not create an array (it was created by a declaration statement), it … | |
Re: [QUOTE=Manutebecker;757431]After reading up on them in terms of class hierarchy, they seem to just be almost like comments, to remind you that all classes use this sort of function[/QUOTE] ???!!! It's a false statement (or I misunderstand the post). | |
Re: Look at the excellent tutorial by Julienne Walker: [url]http://eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx[/url] | |
Re: You (and me) can create a homepage with Notepad only ;) | |
Re: A has-a relationship between classes is not an inheritance (see, for example, [url]http://en.wikipedia.org/wiki/Has-a[/url]). What's a problem? can you describe it more specifically? It's not a question: "I don't know how to write constructors and destructors". | |
Re: 1. Why the last statement of [icode]Student Student::operator+[/icode] is [icode]return false[/icode]? Are you sure that one Student added to another Student is a Student again? ;) 2. Look at braces in this operator body. Why you wrote two braces one after another in if statement? 3. Don't print messages in … |
The End.