6,741 Posted Topics
Re: [B]>Kindly let me know of alternatives of how I could solve this problem.[/B] You're not actually appending to the file, you're appending to lines in the file, which amounts to inserting into the file. Unless you're using a system with record oriented files, your two best options are probably the … | |
Re: [B]>I am not certain where to start.[/B] Then you should consider switching your major. "I don't know where to start" is equivalent to "I'm not cut out for programming". [B]>1. Write a C program that only lists all files in the current >directory and all files in subsequent sub directories.[/B] … | |
Re: [B]>1. Line #8 works (at least my compiler doesn't comply), but line #12 is not allowed. Why?[/B] Because the types are incompatible. It's legal to add a const qualifier as such: [code] int *p = 0; const int *q; q = p; // Okay [/code] Note that p and q … | |
Re: [B]>so we'll deal with 99 useless posts so we don't lose that 1 good one.[/B] The mods can clean up any messes. I've been on forums where threads were automatically closed after thirty days, and it was a somewhat annoying feature. Just because something sounds good in theory doesn't mean … | |
Re: [B]>Is there a way[/B] Yup, there sure is. It's even easier than looking for tokens because you only need to keep a character count (and look for the end of the string, but that goes without saying). | |
Re: [B]>which one is necessary to overload if i would like to make -x understanable for the compiler?[/B] The negation operator is a single argument member function: [code] class foo { public: // Overload negation foo operator- ( const foo& obj ); }; [/code] [B]>If yes, >than the compiler makes double … | |
Re: [code] std::string name; // Get the name... std::ifstream in ( ( name + ".txt" ).c_str() ); [/code] | |
Re: I wouldn't bother worrying too much about speed unless you can prove that your code is slow enough to justify optimizing. | |
Re: [B]>//We want to compare Foo::x here, not the pointers. >bool result = a > b;[/B] That's a very bad idea (even if it doesn't work). You're trying to change the established behavior of an existing type, which could have unexpected effects elsewhere (like when you want to start working with … | |
Re: [B]>I cannot find on the web.[/B] You didn't look very hard, did you? [URL="http://www.cs.caltech.edu/courses/cs11/material/cpp/donnie/cpp-ops.html"]This[/URL] is the first hit from google that I got using keywords from your thread title. | |
Re: [B]>Therfore the previous one is more preferable?[/B] Passing objects by const reference is preferable because it's pretty much always more efficient than passing by value. The reference generally takes up less memory than an object instance, and the cost of a copy constructor call is avoided. | |
Re: I'm intrigued. Please post a complete (small!) program that exhibits the problem. | |
Re: [B]>ok so would it look like this for each cout statment? [/B] Do you even own a book on C++? You're making mistakes that would cause a 1st day beginner to blush in embarrassment. [B]>im not sure how to show how many stars should be given to each range [/B] … | |
Re: [B]>Below is the block of code for your reference.[/B] Are you using a custom allocator? | |
Re: [B]>I don't want to know each and everything in C++[/B] Good. That's probably an impossible goal anyway. [B]>I mean what it takes to be a best C++ expert?[/B] Practice and a constant desire to improve. If you have the latter, you'll find resources to learn from. For example, nobody told … | |
Re: [B]>Sry i was trying to quote from this answer and i accidentally gave -1 at the answer.[/B] I fixed it for you. Now it's back at 0. :) [B]>Can u write the de-allocation of memory in 1 in code pls??[/B] [code] // Allocate T **p = new T*[ROWS]; for ( … | |
Re: [B]>Now the question is how the Assember was implemented, i mean which language?[/B] Any compiler can be written in a suitable existing language. The first assembler was probably hand compiled as machine code. Then the second assembler could be written in assembly language and compiled using the first assembler. [B]>how … | |
Re: [B]>Is storing the object's pointer, and dereferencing it to access >methods/field, faster than storing it as a normal object, and >calling the method/accessing the fields normally?[/B] No. If anything, pointers are slower due to the extra step of chasing the pointer. Member access is the same either way, once you … | |
Re: [B]>can I restore my data back?[/B] There are a number of software packages that "undelete" deleted files, but I wouldn't expect too much from them if I were you. In my experience they're hit or miss (with a tendency toward miss). [i]Real[/i] restoration is a very expensive manual process, so … | |
Re: MyChar is an array of char. a[i] is a single char. The two types are completely incompatible. [ICODE]MyChar[i] = a[i][/ICODE] would work. At least until i gets incremented past 1, then you're accessing a out of bounds. | |
Re: [B]>here is what i have so far (it won't compile)[/B] So what do you want us to do? Finish it up for you, tie it up with a pretty little bow, and send it to your teacher with your name on it? Why don't you try posting what errors you're … | |
Re: Why don't you search the post archives? We get this request regularly, and the questions are almost always identical. | |
Re: [B]>Does anyone have code out there on how to do this?[/B] Correct me if I'm wrong, but isn't the point of the project for [i]you[/i] to write the code? Assuming this is homework, you don't really learn anything by stealing another programmer's code and palming it off as your own. | |
Re: GetData and GetSize are called on objects that are qualified as const. In such a case the compiler has to assume that both of those functions modify the state of the object, so it disallows the call. You can fix it by qualifying the two member functions as const since … | |
Re: [B]>I need to include some standard libraries. >But I dont want to overload them, what is the solution? >I have to use #ifdef ?[/B] Standard headers should manage this kind of thing. Just include the headers and don't worry about it unless you discover a problem down the road. [B]>If … | |
Re: [B]>Prefer a plain int over a short int or a long int.[/B] int (as opposed to short int or long int) has traditionally been the "natural" integer size for the platform. Using this "natural" integer size gives more leeway for optimization at both the implementation level and the platform level. … | |
Re: [B]>any suggestions?[/B] Yes. Be more specific. I mean, if you can't find the row and then overwrite it with strcpy (or something similar, maybe sprintf), you must have a different problem than the one implied by your question. | |
Re: If you want an algorithm, I'd recommend looking for patterns in the traversal results. For example, the root is the first hit in preorder and the last hit in postorder. You can go from left to right in preorder and find the left parent vine (C, B, A in your … | |
Re: The >> operator is default delimited by whitespace. If your strings need to contain whitespace, use getline instead. FYI: [B]>ifstream plainText(inputPath.c_str()); >ofstream cipherText(outputPath.c_str());[/B] This won't do jack because inputPath and outputPath are presently empty strings. You need to open the file after figuring out what the path is. :icon_rolleyes: [B]>while … | |
Re: Add them to your watch list, or view them from the "Autos" section. | |
Re: [B]>However if I define a user defined object, I must initialize it like: >myclass myobj();[/B] Actually, that example is wrong. Due to some grammar issues, myobj in your example is actually a function declaration, not an object of myclass. When creating objects using the default constructor, you [I]don't[/I] include a … | |
Re: You want to compare with the current index, not counter. The value of counter is the number of legit values in the array. Using it as an index in an array that was not completely populated is extremely likely to be undefined behavior. This is the algorithm: [code] int min … | |
Re: [B]>I have no clue on how to do this please help thank you [/B] You'd better learn quickly how to deal with this situation without running to someone else for hand holding. The majority of the time, a programmer has no clue how to do something. That's why it's such … | |
Re: [B]>It should be considered valid, but it's not.[/B] Direct comparison of floating-point values is risky because some values might not be exact, and the comparison will produce an unexpected result. You should take care to use a fudge factor when doing this kind of comparison: [code] #include <stdio.h> #include <stdlib.h> … | |
Re: [B]>if(strcmp(caracter,argv[1]))[/B] strcmp returns a comparison, not a boolean. In other words, 0 is a match and non-zero is a failure to match. Thus, your if statement is reversed. You print the line when it doesn't match argv[1]. This should work better: [code] if ( strcmp ( caracter, argv[1] ) == … | |
Re: Good god, can't you come up with something a little more specific? | |
Re: [B]>If not, guide me toward proper etiquette.[/B] Code is nice, but if you're getting an error, it's helpful to post that as well. | |
Re: [B]>-How can i make the array any size, so it can quit on the 2nd >number entered or the 27th number entered?[/B] That really has nothing to do with the array size. The histogram array only has ten elements, and each element is a count of the numbers that fit … | |
Re: [B]>Think about the relationship described by inheritance, >and why what you're doing isn't possible[/B] And yet it [i]is[/i] possible. What the OP wants to do is called downcasting. It's not recommended for the obvious reasons, but it's a feature that C++ supports using dynamic_cast because it's sometimes necessary: [code] #include … | |
Re: >I can't see any other way to pass the ... arguments, other than >through the "va_list args" and va_start lines, am I wrong in thinking that Nope, you're right on track. | |
Re: [B]>Is C++ the easiest language ever?[/B] No, it's one of the hardest. [B]>anybody know how to help?[/B] Nope. Your question is about as close to incoherent as they get. Can you try to make more sense? | |
Re: [B]>myarray.clear(); //Doesnt deallocate the memory[/B] Correct. Clearing the array only changes the size. [B]>myarray.reserve(0); //Doesnt deallocate memory[/B] Correct. Reserving space only causes reallocation if the new size is greater than the current capacity. [B]>myarray.swap(myarray);//Doesnt deallocate memory[/B] This isn't required to shrink-wrap the capacity. You [i]might[/i] have better luck with a … | |
Re: [B]>Hmm, That's very odd![/B] Not especially, though it can be surprising. This is the underlying problem: [code] #include <iostream> #define UNICODE #include <windows.h> int main() { TCHAR *s = L"test"; std::cout<< s <<'\n'; } [/code] My crystal ball says the UNICODE macro is defined, which causes CString to resolve to … | |
Re: Just use a pointer to a function for the callback: [code] #include <iostream> class foo { int _i; int _limit; void (*_action)(); public: foo ( int limit, void (*action)() ) : _i ( 0 ), _limit ( limit ), _action ( action ) {} bool done(); }; bool foo::done() { … | |
Re: [B]>I don't understand how to add a char * member to points to a string.[/B] Look at the Cd class and do the same thing with your child class. The Cd class has char* members as well, so it's not like you don't have an example to work from. :icon_rolleyes: | |
Re: [B]>Use a database.[/B] Use your brain. This guy is clearly a beginner, and you want him to struggle with a database API on top of basic C++ for a trivial problem? [B]>I've tried so hard,but so far i still cant figure out what is the actual way to do this....[/B] … | |
Re: Mixing C++/CLI and standard C++ can be troublesome. Try sticking to one or the other unless you have good reason not to: [code] label2->Text = Convert::ToString ( a ); [/code] | |
Re: You're working with uninitialized pointers. Pass the matrices as references: [code] void generate(int**&, int, int); void fill(int**&, int, int); int** compute(int**& ,int**&, int, int, int, int); void dellocate(int**& val, int x, int y); void display(int**& val, int x, int y); [/code] Match that in the definitions, and that's the only … |
The End.