1,296 Posted Topics
Re: I can't understand what the OP snippet illustrates. By the way, reserve member argument defines new [b]total capacity[/b] but not capacity increment. Evidently, all pointers and references to vector elements are valid while [icode]v.size() <= v.capacity()[/icode]. That's because std::vector must have continuous storage for all its elements (by standard requienment). … | |
Re: Line by line, word by word: [code=cplusplus] void WordByWord(const char* filename) { if (!filename) return; ifstream file(filename); string line, word; for (int lineno = 1; getline(file,line); lineno++) { cout << "Line #" << lineno << ":\n"; istringstream words(line); while (words >> word) cout << word << '\n'; } } [/code] … | |
Re: 1. Why semicolon after else? [code] else; // empty alternative?! cout << ... [/code] 2. [icode]string toString();[/icode] - the function returns string value, not a reference to anything. Now [code] List[K].toString() = "DELETED"; [/code] is absolutely senseless assignment to a temporary string value returned from toString() - in other words, … | |
Re: Alas, you need some (serious) redesign, for example: [code=cplusplus] double radius ( double& r, double& d, double& c ); double diameter ( double& r, double& d, double& c); double circumference ( double& r, double& d, double& c); const double Pi = 3.14159265358; int main() { double r, d, c; int … ![]() | |
Re: You forgot to allocate +1 byte for zero char terminating C-string: [code=cplusplus] p = new char[strlen(s)+1]; [/code] Now you have memory leak: you forgot to deallocate this memory: [code=cplusplus] delete [] p; [/code] Well, it's evidently useless function... The 2nd snippet: [code] char* s; ... cin >> s; [/code] Pointer … | |
Re: Look at Project Properties|Linker|System and set the proper Stack Reserve Size parameter (in bytes - for example, set 3000000, see seedhant3s calculations). May be your IDE (VS 2005) has slightly different names for these parameters (I have VS 2008 now). Better try to avoid large local (automatic) array allocations, especially … | |
Re: It works: [code=cplusplus] template <typename T> class Sample { private: typedef std::vector<T> vectorType; vectorType vector; public: typedef typename vectorType::iterator vectorIterator; vectorIterator begin(); }; template <typename T> typename Sample<T>::vectorIterator Sample<T>::begin() { return vector.begin(); } [/code] An example from the C++ standard: [quote][code] template<class T> struct A { typedef int B; A::B … | |
Re: If you mean [i]variable argument list[/i], read this: [url]http://www.codeproject.com/KB/cpp/argfunctions.aspx?fid=15556&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=1066108[/url] | |
Re: >where am i going wrong??? here, there and everywhere ;) 1. What for floatSize? You never used it. 2. sizeof(bits) is a size of a pointer to unsigned char. It's not bear a relation to the problem. Fortunately it's equal to 4 on 32-bit CPU... 3. 128 as a bit … | |
Re: Declare class table member functions with [b]const[/b] parameters: [code=cplusplus] bool insert(const TKT& inskey, const TDT& insdata); ... [/code] Consider [icode]anytable.insert(6,"john")[/icode]. It's impossible to bind non-const std::string reference to char array "john". However it's possible to bind const std::string reference to temporary std::string object produced by "john" => std::string("john") conversion. Yet … | |
Re: See [url]http://www.codeproject.com/KB/cpp/number_to_text_converter.aspx[/url] It's a program in C (I don't know why it's contained in .cpp file). Change sacramental [icode]void main[/icode] to standard [icode]int main[/icode]. It works (at least for 15000, 1500, 150 and 15 ;))... | |
Re: [QUOTE=arenq;872814]Can you tell me which basic operations on a list can cause an use of stack proportional to the size of the list? (I mean, looping on all elements...) I have problems with stack size. Is iterator post-incrementing dangerous in this sense?[/QUOTE] No need in recursive implementation of basic list … | |
Re: [code=cplusplus] #include <algorithm> ... std::random_shuffle(a,a+10); [/code] or with PRNG seed: [code=cplusplus] #include <algorithm> #include <ctime> ... srand(time(0)); ... std::random_shuffle(a,a+10); [/code] | |
Re: No such library function: it's not well-defined specification. For example, how about this delimiters set: [code] { "!", "#", "#!" } [/code] ? Elaborate non-contradictory specifications. It's not so hard to write a proper tokenizer in C... | |
Re: In modern C++ [i]condition[/i] is not the same thing as an expression. A condition can be a declaration, that's an example from the Standard: [code=cplusplus] int i = 1; while (A a = i) { //... i = 0; } [/code] | |
Re: [quote]An aggregate is an array or a class (clause 9) with no user-declared constructors (12.1), no private or protected non-static data members (clause 11), no base classes (clause 10), and no virtual functions (10.3).[/quote] It's possible to initialize class CA object (see OP) with [i]initializer-clause[/i] { ... } in the … | |
Re: 10..20 or 11..19 or what else? [icode][0,n)[/icode] - 0, 1, ... n-1 : [code] rand() % n [/code] | |
Re: [QUOTE=preetchhabra;871368]i am new in programming in visual c++ can anyone tell that how can i call one form from other form means by clicking on button first form should disappear and second fom should come on screen in visual c++ 6[/QUOTE] No [i]forms[/i] in 11-years old Visual C++ 6... | |
Re: Of course, you got memory access exception: initial head == 0 but you are trying to assign new node pointer via this null pointer: [code=cplusplus] head->name = new char ... [/code] Regrettably you did not set the language specifier into the code tag so no line numbers in your snippet. … | |
Re: There are lots of PDF libraries for C and C++. For example, look at [url]http://www.freebyte.com/programming/cpp/#freecpppdflibraries[/url] (it's not a complete list). I'm sure that you need 32-bit C++ compiler (as soon as possible, not only for pdf libraries)... | |
Re: >any suggestion on where to start? Start from [url]http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx#merge[/url] | |
Re: Try winbgim or winBGI libraries - BGI for Windows (search Google). Regrettably (or fortunately), I have never used these libraries... | |
Re: Place this function into the separate .cpp file: [code=cpluplus] void ShowText(const char* filename) { ::ShellExecuteA(::GetDesktopWindow(), "open", "notepad.exe", filename, 0, SW_SHOWNORMAL); } [/code] Include <windows.h> dependency into this file only. This function works in console applications too. | |
Re: >what is a good way to initialize a variable in a function, just once? [code=cplusplus] ... f(...) { static bool var = true; ... } [/code] As usually, it's a symptom of a bad design ;)... | |
Re: I don't understand why you don't understand... ;) Line #15: unitialized variable guess is compared with random. Unitialized means that the value of this variabe is undefined: it's a garbage. You will get the value in the next statement! Back to the Future game... No comments... | |
Re: Are you sure that the best method to avoid a threat is to cry: "Keep out of my sight!"? | |
Re: That's it: [code=cplusplus] if ( top_ == size ) resize(); [/code] See what happens: 0. empty stack of size 1 (for simplicity); top_ = -1 1. push; top_ != size, OK, top_ = 0 now, stack full! 2. push again: WARNING: top_ != size, NO resize!!! ... ... and you … | |
Re: [QUOTE=saw iv;869952]i want from any one to write the following programme for me i want it by graphics & off course i want the full programme i want the programme written in borland c++ [U] The programme:[/U] it is required to build an application which simulates the famous connect-4 game. … | |
Re: [QUOTE=newcook88;869935]how do i create a set method to get the fstream input file. in need to be able to define the file location in the main method. [CODE]class a { private: ifstream fileOne; ofstream report1; public: void setinput(std::ifstream& in); void setoutput(std::ofstream& out); }; [/CODE] how can i code these set … | |
Re: >i hope i did tag right on code posted. Alas, correct tags are: [noparse][code=cplusplus] source [/code][/noparse] | |
Re: Read this: [url]http://www.ddj.com/cpp/184401305[/url] | |
Re: [QUOTE=khalf;869894]i have the same problem[/QUOTE] You have the same solution. Are you sure that it's a good idea to reanimate 3-years old thread? | |
Re: What is it: [i]abstract values[/i]? May be you mean [b]absolute[/b] value? reinterpret_cast considered harmful ;) [code=cplusplus] typedef std::basic_ifstream<short> ishortints; typedef std::basic_ofstream<short> oshortints; void doIt(const char* source, const char* target) { if (!source || !target) return; ishortints fraw(source,ios_base::binary); oshortints fabs(target,ios_base::binary|ios_base::app); short x; if (fraw && fabs) while (fraw.get(x)) { x = … | |
Re: 1. Next time use code tag with the language specifier: [noparse][code=cplusplus] source [/code][/noparse] 2. Double apostrophes (empty character constant) is not a valid construct in C++ (have you ever seen the compiler diagnostic messages? ): [code=cplusplus] cout<<str2+''+str3+''+str1<<endl; [/code] Use ' ' for the space character. | |
Re: [code=c] if (x - y + abs(x-y)) { /* x > y */ [/code] ;) | |
Re: Probably you place class implementations in .h files (at least for gameSequence and difficultySelection classes). That's why you have gameSequence.obj object module (see diagnostics in OP), for example (correct .h files w/o implementation codes are never produced object modules). Of course, after that you have these classes implementation in every … | |
Re: If the program runs on a little-endian computer: [code=cplusplus] inline std::string int2String(dWord n) // unsafe programming { char* p = reinterpret_cast<char*>(&n); return std::string(p,sizeof n); } [/code] Platform-independent (more precisely, LSB/MSB-independent) code is a few cumbersome... Apropos, your [icode]*reinterpret_cast<dWord*>(...)[/icode] expression is not portable at all: how about proper (for dWord* pointer) … | |
Re: >i began reading K&R ... Well, let's read the next sentence after squeeze function definition: [quote]Each time a non-c occurs, it is copied into the current j position, and only then is j incremented to be ready for the next character. This is exactly equivalent to [code=c] if (s[i] != … | |
Re: See also ToLowerInvariant() function: [url]http://msdn.microsoft.com/en-us/library/system.string.tolowerinvariant.aspx[/url]. MS recommends ToLowerInvariant for OS identifiers (file names, registry keys etc)... | |
Re: [QUOTE=daviddoria;869304]I want to make an input stream parser capable of handling input in any of the following forms: [code] x y z x,y,z x, y, z (x,y,z) (x, y, z) [/code] Is there a clever way to do this? Or do I have to check the first character, if it … | |
Re: [QUOTE=dav555;869241]how can i convert a hex value of a byte (unsigned char) to a short value? [code="c++"] unsigned char hexByte = 0x02; short value= ??? [/code] thank you for your help![/QUOTE] As usually: [code=cplusplus] short value = hexByte; [/code] What's a problem? | |
Re: You can't run this program; moreover, you can't compile it: [code=c++] int *result=pfact(n); // You declare a pointer to int for (int i; result[i][0] !=0; ++i) { // You are trying to subscript result if(result[i+1][0]!=0) ... // result[i] is int and now you are trying // to index this int … ![]() | |
Re: And what for friend arith operators? [code=cplusplus] fraction operator+(const fraction& f) const; ... [/code] | |
Re: No problems with v1 and v2: these members constructors create empty vectors. You can initialize them in Grid constructor(s) or later in the special member function (let it's named as init or what else), for example: [code=cplusplus] explicit Grid::Grid(size_t n): v2(n), v3(n) {} // or void Grid::initv2(const std::vector<int>& v) { … | |
Re: The answer: use anonymous namespace... [code=cplusplus] using std::cout; class A // External linkage name { public: void f() { cout << "::A:f()\n"; } }; namespace { // Internal linkage area: class A // Internal linkage name { public: void f() { cout << "LocalA::f()\n"; } }; typedef A LocalA; // … | |
Re: Yet another approach (undestructive test): [code=cplusplus] bool is1in2(const int* a1, const int* a2, int n) { int j; for (int i = 0; i < n; i++) { for (j = 0; j < n && a[i] != b[j]; j++) ; if (j == n) return false; } return true; … | |
Re: >I looked on google ... After ~15 seconds: [url]http://www.codeproject.com/KB/recipes/csha1.aspx[/url] [url]http://www.packetizer.com/security/sha1/[/url] What's a problem? | |
Re: Simply tell the story: [code] open input file if the file is not opened print message stop endif // read_the_next_record means: // read hours, payrate, Overtime, Regpay while read_the_next_record is OK ... see OP pseudocode endloop close input file [/code] Pseudocode is not a formal language. Your teacher's pseudocode != … | |
Re: >Class declaration means... Between you and me: this constuct called a class [b]definition[/b] in the C++ Standard... ;) | |
Re: [QUOTE=tux4life;853321][ICODE]ofstream infile;[/ICODE] // create a new output stream [ICODE]infile.open ("[I]yourfile[/I]", fstream::app);[/ICODE] // open the file for appending[/QUOTE] Output stream named [b]in[/b]file... That's cool! ;) |
The End.