537 Posted Topics
Re: [quote][code]vector<MyClass> MyVector; MyVector.push_back(MyClass(Param1, Param2, Parm3, Param4));[/code] As I understand this would involve creating two instances of the object and copying one to the other. Is that correct?[/quote] As I see it, you are creating one instance of 'myclass' which pushed into the vector. [quote] Would it run quicker if I … | |
Re: [url]http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles4.html[/url] | |
Re: You appear to be lost and overwhelmed held captive in a class that probably has no relevance whatsoever to your degree major. What you need is a strategy to tackle this seemingly overwhelming task. If you look at this thing in it's entirety, yes.. it does look like some intense … | |
Re: Why ruin a good thing you already got goin'? [CODE] //this gets(employee[counter].name); //should be this cin >> employee[counter].name;[/CODE] I am really not sure where you got "gets()" from.. I think it's a C function... and if I'm not mistaken it's use can be somewhat dangerous. In my opinion, it is … | |
Re: would this be anything close to what you need...? [CODE] void TicTacToe::postMove(int row, int col, char value) { theboard[row][col] = value; showBoard(); }[/CODE] | |
Re: I found [URL="http://msdn.microsoft.com/en-us/library/ty2ax9z9(VS.80).aspx"]this[/URL] article at msdn: [quote] The multiplicative operators take operands of arithmetic types. [COLOR="Red"]The modulus operator (%) has a stricter requirement in that its operands must be of integral type.[/COLOR] (To get the remainder of a floating-point division, use the run-time function, fmod.) The conversions covered in Arithmetic … | |
Re: [CODE] //Write a program that creates an array dynamically whose pointer must not change const int* array = new int[size]; //initialize the array to random values between 0 and n (inclusive) using rand () for(int i=0; i<size; i++) array[i] = rand()%(n+1); //then pass the array to a function that takes … | |
Re: This one is pretty decent: [url]http://www.codeblocks.org/[/url] Not as easy as it used to be.. you could easily start a 'project' as opposed to a 'c++ source' which will mess things up. The debugger is kinda wack. Also, it forces you to save work you haven't even created yet. If you … | |
Re: After briefly looking at your code.. maybe all it needs is just a space in between commands: [CODE] //this strcpy(str, "taskkill /f /im"); //might work if it was like this: strcpy(str, " taskkill /f /im");[/CODE] | |
Re: Move on through your C++ at a rate at which you understand the material (for the most part) and then begin to tackle the next concept. | |
Re: I would be more than happy to help you.. however, I cannot read a bit of that antiquated C code that you have posted in this C++ forum... | |
Re: Here is recent help given to one of your classmates: [url]http://www.daniweb.com/forums/post1070744.html#post1070744[/url] | |
Re: [quote]I'm trying to do a concatenation function I do not want to you use the strings property where we can add strings, I need to add two strings and save them in one string without the use of addition "+"[/quote] Instead of trying to decipher your code, I will offer … | |
Re: [quote]I have to read 16 bytes using the low-level function call read() (in C). After I read the first 16 bytes, the next time I need to read from the same file, I'll only have to read it from until the point it was read before.. [/quote] Since you only … | |
Re: You seem to have mentioned that you have attepted to make some sort of effort at seeking a solution to the problem. I'm sure myself and others would be highly interested in seeing what you have come up with thus far; thereby seperating yourself from the masses of "please do … | |
Re: You seem interested in reading in a file until you reach a delimeting comma. In this case, I recommend use of [URL="http://www.cplusplus.com/reference/string/getline/"]getline()[/URL]. There are a few different getline() functions floating around in the c++ world. The one we are using (and most popular in file i/o) is derived from the … | |
Re: [quote]I have everything I need in the code except the "between 100 and 1000." [/quote] [CODE] //Line #28 should be this: popList[i] = rand( ) % 901 + 100 ; [/CODE] | |
Re: I will offer few improvements to your code and propose a possible pseudo-coded solution to your initial question. Firstly, reading in an entire file character at a time is inefficient should be avoided. There may be some situations where this approach may be warranted; however, I believe that this isn't … | |
Re: I think the problem is here... [CODE]for (int i=-1;ip!=" ";[COLOR="Red"]i--[/COLOR])[/CODE] Since you are using the 'end' flag in seekg(), all offset is relevent to the end of the file.. therefore, you should increment your way from the end of the file, stepping your way backwards into the text file. You … | |
Re: What part of the assignment is giving you difficulty.. ? After breifly looking at your attachment, it seems that the assignment is already well outlined for you.. all you have to do is create a simple child class with one additional attribute that will identify the primary work on the … | |
Re: Looks like ye' need to perform a good ol' [URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045689663&id=1043284385"]int-to-string conversion[/URL]. Today we'll be creating an 'ostringstream' object derived from the <sstream> library in order to facilitate our int-to-string needs: [CODE] #include<sstream> #include<string> #include<iostream> using namespace std; int main() { ostringstream int_to_str; string temp; int a = 0; cout << … | |
Re: FirstPerson... I think the OP asked for a nested for loop :P | |
Re: What you are asking for can be a very useful data structure... if created dynamically can have about the same performance as a vector and might even be more efficient (a vector might allocate more memory than what you actually need based on the number of push_back() opearations) In either … | |
Unfortunately in c++, there is really no good way go locate lines in your file without reading the entire file 'character at a time.' So, if you [I]have[/I] to read only a single line from a file, we know we are at some point going to have to be inefficient... … | |
Re: try this string parsing algorithm to split your line up into individual strings: [CODE] #include<string> #include<vector> int prev = 0; int curr = 0; string temp; string line = "The man is 67 years old and driving an Oldsmobile Rocket 88"; vector<string> vstring; do{ prev = curr; curr = line.find(' … | |
Re: Here is documentation for[URL="http://www.opengroup.org/onlinepubs/009695399/functions/getcwd.html"] getcwd():[/URL] | |
Re: Here is one possible way: [CODE=c++] int i = 0; int line = 0; int number = 0; char c = '\0'; string temp; //Make sure your file is opened in binary mode when manipulating file pointers infile.open("C:\\Documents\\test.txt", ifstream::binary); cout << "Enter line number to read from file: "; cin … | |
Re: right now all that I see that might cause stack overflow might be this.. [CODE] std::vector<BaseEntity> BaseEntity::sm_vEntities = std::vector<BaseEntity>(100000); [/CODE] | |
Re: Does anyone understand this...? or is it just me... | |
Re: I imagine this would require some sort of DLL injection.. where applications would send messages back to your program about their status, specifically if they have the input focus.. window is active or minimized. I believe the last chapter of "Advanced Windows" by Jeffrey Richter covers dll injection, reading and … | |
Re: I find the concept of polymorphism (inheritance) to be a quite interesting topic.. although I am by no means an expert in this (I just do enough of this to get by) I believe it is a powerful OOP concept and in my opinion, is probably the main construct that … | |
Re: Here is just one possible solution to the first part of the problem, there are probably much better loop(s) you can come up with but I am lazy. It is pretty much self explanitory. You can give the second part of your problem a try. Let me know if you … | |
Re: [quote]Important to know is that this file also only can consist of one line.[/quote] [quote] 3 lines in a file:[/quote] Do you people not speak english as a native language... or enjoy confusing the rest of the world. Here is an important excerpt from, [URL="http://catb.org/~esr/faqs/smart-questions.html"]"How to ask questions the smart … | |
![]() | Re: People always ask, "Why do you always have to initialize your variables?" This is why: [CODE] //Here you create something. It is never initialized; therefore probably contains some sort of value.. what exactly it contains, we don't know. long double points;[/CODE] So when you start using this varible for accumulation, … ![]() |
Re: Do you mean like this? [CODE] str1 += str2; str1 += str3; str1 += str4; str1 += str5; cout << str1; [/CODE] | |
| |
Re: The recommended scheme for File I/O is to create an fstream object, attempt to open a file, perform error checking, and load the file. The code in question is performing error checking to see if the file was actually opened. It is quite possible that the file may have been … | |
Re: [quote] How can I check whether my code has memory leak or not? [/quote] [LIST] [*]objects allocated memory using 'new' must be deleted. [*]anytime you access an array out of bounds [*]anytime you try to dereferrence a NULL pointer. [*]anytime you leave a dangling pointer, for example: [/LIST] [CODE] int* … | |
Re: [CODE] //This char * DecData = new char (stringlen+1); //Should be this: char* DecData = new char[(stringlen+1)]; //This int * NewData = new int (strlen(Data)); //Should be this: int* NewData = new int[(strlen(Data))]; [/CODE] | |
Re: [quote] But how do I do this without knowing which name that object got?[/quote] Give ye' who is nameless a name: [CODE] point* mypoint = new Point(Point::SPHERE, 300.0f, i); out.add_primitive(obj, mypoint); [/CODE] | |
Re: [quote]How could i make the program that could limit the input integer the user try to enter[/quote] [CODE] int x=0; //Force user compliance..!!! do{ cout << "Enter a number between 1 and 20: "; cin >> x; if(x<1 || x>20) { cout "\aNumber out of range, try again!"; } }while(x<1 … | |
Re: I'm not sure right off hand what is going on, but here is a couple of things that I like to try when the unexpected starts to happen in my file i/o operations: [LIST] [*]try opening your file in binary mode [*]it seems like you might be using your ofstream … | |
Re: These variables are uninitialized and could contain any value that happened to reside in their memory location at the time of their creation: [CODE] //These could be any value..! we don't know what they are..! int x,factorial; [/CODE] How can x equal 1 and 0 at the same time? [CODE] … | |
Re: Although I am not an inheritance expert, I have a feeling your inputInfo() outputInfo() functions of your [U]parent class[/U] need to be labeled 'virtual' because they are overridden in the child class. | |
Re: try making this small adjustment to your 'while' loop condition: [CODE] while((score < 0 || score > 100) && (score != -999)); [/CODE] | |
Re: By doing this, you have established a direct relationship between the two arrays: [CODE] //We can assume that 'votes[3]' corrosponds to 'candidates[3]', for example. if ( inFile >> candidates[i] >> votes[i] ) [/CODE] So all you really need to do is extract the largest value from the votes[] array: [CODE] … | |
Re: [CODE] //Loads the array with ascii values ranging from 65 to 122 ('A' thru 'z') static_cast<char>(array[i]) = rand()%58 + 'A';[/CODE] |
The End.