6,741 Posted Topics
Re: >What are your recommendations? Download Bloodshed's Dev-C++. If you like it then it should suffice for the time being and not cost you anything. | |
Re: >char [size] name; Good suggestion, bad code. You seem to be mixing and matching features of C++ and Java to create something completely incorrect for both. Try this instead: [code] char name[size]; [/code] Where size is a suitably defined constant value, in this case 5. | |
Re: For somewhat obscure reasons, operator<< should be a non-member function: [code] ostream& operator<< ( ostream& out, const Log& log ) { log.writeLog ( out ); return out; } [/code] If Log doesn't have a public interface that allows everyone to write the log somewhere, you'll need to make the function … | |
Re: I would imagine that you initialize encryption with asterisks, right? So let's walk through the execution with that assumption in mind: [code] for ( int i = 0; i < 5; i++ ) [/code] You create i and set it to 0. Since i is less than 5, the body … | |
Re: cin's operator>> uses whitespace as a delimiter: [code] string s; cin>> s; // Type "John Doe" cout<< s; // Prints "John". "Doe" left in the stream [/code] >I tried flushing the input buffer with cout.flush() What made you think that calling the flush member function of an output stream would … | |
Re: This is a simple program. Are you trying to get other people to do your homework? | |
Re: Code tags don't help much if your code isn't formatted to begin with. >what is the proper code inside the < operator? That depends on the needs of the class. Does it make more sense to compare by first name, last name, or both? How you define operator< depends heavily … | |
Re: >If linux is so great and so much better than microsoft, then how come each >newer version becomes more and more like Windows? Linux vendors want the desktop market, so they have to dumb things down enough to entice the average Windows user. Of course, that's just my opinion as … | |
Re: Congratulations, you've just discovered the difference between theoretical upper bounds and real world implementations. In theory, merge sort is slightly faster than heap sort. In practice, the merge sort algorithm could be implemented poorly (or naively) and heap sort will blow it away. | |
Re: When you need to read an unknown number of records, you have three choices: 1) Read and process one record at a time: [code] struct student stud; int i; while (fgets(stud.name, sizeof stud.name, in) != NULL) { for (i = 0; i < 5; i++) { if (fscanf(in, "%d", &stud.marks[i]) … | |
Re: >Well u can always use STL's "for_each" for efficiency, readability, portability & usability. for_each isn't nearly as useful as the propaganda suggests. Also, for_each would be a poor solution to the issue that this tip covers. A better solution would be generate_n, but that's still not as concise and easy … | |
Re: What you want to do is not possible in standard C++. You seem to think that a file stream knows if the external device is available if you remove it between construction and destruction of the stream. In reality, all you're doing is invoking undefined behavior by writing to a … | |
Re: >#include <stdio.h> >#include <iostream.h> >#include <stdlib.h> This are no longer valid C++. Use this instead: [code] #include <cstdio> #include <iostream> #include <cstdlib> using namespace std; [/code] >void main() No! void main is not, and never has been, correct C++. main returns int: [code] int main() [/code] >int ave, 1st, 1:2, … | |
Re: An IP is a four byte address representing a network node (ie. a computer or network) under the internet protocol (hence the name, IP). IPs are used for locating other nodes on a network to establish a communication link. Without an address, it would be very hard to find a … | |
Re: Let me spell something out for you nice big letters: [SIZE=7][B]We will not write your program for you.[/B][/SIZE] If you want help, we'll help, but freebies are not help. | |
Re: >don't I have it declared in the float line?? No. If you had preceded it with a comma instead of a semicolon then yes: [code] float qty=0, val=0[COLOR=Red][B][SIZE=7];[/SIZE][/B][/COLOR] price=0; [/code] | |
Re: It's hardly a strange problem since everybody sees it when learning C or C++. getline reads characters until a newline character is encountered, but cin>> leaves newlines on the stream. So a cin>> followed by a getline will typically cause problems. >As always, I appreciate your help Apparently not enough … | |
Re: That's your last chance, "dear". You've broken rules left and right while not contributing anything useful to the forum [b]despite[/b] multiple warnings through both thread and PM. | |
Re: 1) You need to include <string> because you try to use the string class. 2) You need to qualify each use of string with std::. 3) You can't initialize arrays in a class declaration. 4) Because of 3, you must supply a size for the arrays. | |
Re: >the search shoud work like this Okay...and what [b]does[/b] it look like? Sorry, but I'm not nearly interested enough in your problem to compile and debug your code to find out what's wrong. You'll have to tell me what your problem is to get help. However, I [b]am[/b] interested enough … | |
Re: Allow me to paraphrase and offer an official response. >"C and C++ are different languages" Yes they are. Properly written C will likely break when compiled as C++ for any non-trivial program, and properly written C++ is barely recognizable as "something like" C. >"Most C++ looks like C" Yes, but … | |
Re: >Just get garbage when I write it to disk. You said you were using fstream. Would that be fstream::operator<<, or fstream::write? Since Borland supplies you with AnsiString, it makes sense that they would also provide an overloaded operator<< for it as well. At the very least, IIRC, AnsiString has a … | |
Re: >people form biased opinions of people based on where they're located. Perhaps, but it's more likely that one would form a biased opinion based on one poorly worded post, a first impression in the Introduction forum, or any number of trivial things that occur often. I think the entire issue … | |
Re: >I Dont know why i like this forum It's the girly purple. Everyone loves girly purple, even those who say they don't like girly purple. :) | |
Re: >I have two problems with this. No, you have one big problem. Binary reads and writes are undefined on non-POD classes, such as AnsiString. You would be better off avoiding binary oriented files until you know what the pitfalls are. | |
Re: Bike (incorrectly) derives from Wheel, so you need to supply a constructor call to the base class. If one isn't make explicitly, it's provided for you using the default constructor. Try this: [code] Bike::Bike(int f, int b): Wheel(0), front(f), back(b) {} [/code] Of course, 0 is probably not an appropriate … | |
Re: >It isn't even for me. You sure used "I" a lot if it's not for you. You also seem to care quite a bit even though it's not for you. This strikes me as one of those "Hey, Doctor, my friend has this embarrassing problem" stories. :D It seems to … | |
Re: [code] #include "pctimer.h" ... pctimer_t begin = pctimer(); /* Code that you're timing */ printf ( "Time elapsed: %f\n", pctimer() - begin ); [/code] | |
Re: If you try to write the structure object to a file, you'll basically be doing a byte-by-byte copy to the file. That's bad because one of your members appears to be a non-POD type (String). A byte-by-byte copy on a non-POD type will likely not work, and because it's undefined … | |
Re: It's a good thing you thanked us in advance, because you certainly wouldn't thank us after we told you that this isn't rent-a-coder-for-free.com. | |
Re: >plz tell smething more abt my problm. How about we skip the part where I call your code crap with examples and I just give you a better version: [code] #include <iostream> #include <fstream> using namespace std; struct computerspec { int ram; int hdisk; }compuspec; int main() { char ch; … | |
Re: >My e-mail add is:tlhokomelo@webmail.co.za We don't care because we're not going to be emailing you anything. >but I can not afford to buy books on the subject Somehow, I doubt that unless you can't afford to [url=http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html]download a file[/url]. >Or tell me of a site I can get a lot … | |
Re: >Is there a way that I can a more precise time so that I can get a time for every method The most precise method is use of a profiler program or a framework written using some platform or compiler specific function. If you want to use clock_t and clock, … | |
Re: How about posting a compilable example? Like, with your header includes and driver and the complete function so we can do more than just guess? | |
Re: >Any ideas on coding this. Yes, plenty. However, what [B]I[/B] think doesn't matter since it's [B]your[/B] program. What did you come up with before posting here? | |
Re: >Can you please help me on calling interrupts in that standard? Didn't you already ask that question, or was it someone else? >By I think, one of the h files can be used for this purpose. windows.h, and you have to implement the functionality yourself: [code] #include <windows.h> void gotoxy … | |
Re: [url]http://mathworld.wolfram.com/ScientificNotation.html[/url] | |
Re: IIRC: [code] pow ( abs ( val ), 1.0 / 3.0 ) [/code] | |
Re: Sure it can be written differently. What's the goal of the function? | |
Re: Please don't bump ancient threads. Locked. | |
Re: push_back requires that you pass an existing object as the argument: [code] vector<int> v; int x; cin>> x; v.push_back ( x ); [/code] You solution is to use a loop: [code] while ( cin>> x ) v.push_back ( x ); [/code] | |
Re: Change this: [code] int numb, tot, count, sum; [/code] to this: [code] int numb, tot, count, sum = 0; [/code] sum was uninitialized for the first run, but after the first run you set it to 0, so the second and third runs work properly. | |
Re: >1. Explain why the following program is illegal in standard C/C++. It's illegal for more reasons than your instructor probably knows. ;) First, cout is used without including <iostream> and qualifying for the std namespace. Second, main doesn't return void, it returns int. Third, variables can only be used in … | |
Re: What have you tried? Prove that you've made [b]some[/b] sort of attempt or you won't get much help. | |
Re: >"I'm going to kill your computer if you dont enter the right password!!!" Uh huh. >main(); //go to main to do until success It's illegal to call main recursively in C++. >teach me how to only let the user have 34 tries before it close [code] // Pseudo-C++ int n … | |
Re: You need to define an operator>> that looks for an object of your enum: [code] #include <iostream> #include <stdexcept> using namespace std; enum X { A, B, C }; istream& operator>> ( istream& in, X& x ) { int val; if ( in>> val ) { switch ( val ) … |
The End.