2,712 Posted Topics
Re: 1)Find all C++ reserved keywords online. 2)Insert the reserved keywords in order into map. 3)Read in word by word from the text file 3.a) For each word check if it needed word exist in the map 3.a.1) If not then "forget about it" 3.a.2) If so then doStuff with it | |
Re: and why can't you try this in a C++ compiler? | |
Re: to convert to a string use this function : [code] #include <string> #include <sstream> #include <iostream> using namespace std; template<typename T> string toString(const T& arg){ std::streamstream ss; ss << arg; return ss.str(); } int main(){ cout << toString(123) << endl; cout << toString(12.345) << endl; } [/code] | |
| |
Re: First some design problem. This function is pretty bad : [code] void attackplayer(Player& hero, bool checkup, bool checkdown, bool checkleft, bool checkright){ if (checkup == true || checkdown == true || checkleft == true || checkright == true){ hero.damage(damage); } } [/code] First an obvious way to make this better … | |
Re: If its only 1-3 length, then just hard code it like so : [code] int toInt(const string& str){ int result = 0; switch(str.length()){ case 1: result = str[0] - '0'; break; case 2: result = (str[0]-'0')*10 + (str[1] - '0'); break; case 3: result = (str[0]-'0')*100 + (str[1] - '0')*10 … | |
Re: Seems like a homework problem to me. But you need to use the following : 1) Polymorphism 2) Classes 3) std::vector 4) virtual functions 5) Inheritance | |
Re: Why do you have 2 isDead function? From your code, it seems like isDead function needs to be just a function like so : [code] struct Particle{ float posX, posY; }; bool isParticleDead(const Particle& p){ return isOutOfScreen(p);} int main(){ list<Particle> p; p.push_back( Particle() ); p.push_back( Particle() ); p.remove_if(isParticleDead); } [/code] | |
Re: The derived object is not the main focus, its the base object. By the base object being able to point to the derived object, it calls Derived::print function, if it in fact points to a derived object else it calls its own. Of course this assumes print is a virtual … | |
Re: Here is C++ version just because I'm feeling nice today. [code] #include <iostream> #include <vector> #include <string> #include <algorithm> #include <iterator> #include <sstream> using namespace std; template< typename T> struct EqualCheck{ T rhs; EqualCheck(): rhs(){}; EqualCheck(const T& Rhs) : rhs(Rhs){} bool operator()(const T& arg){ return arg == rhs; } }; … ![]() | |
Re: Its pointless doing this since, you are using string, unless you are doing this as an exercise. [code] string text = "This is the text I want to search in"; string wordToFind = "want"; bool isFound = text.find(wordToFind) != string::npos; [/code] | |
Re: [QUOTE=j-green.10;1243286]I have a string that includes numbers and letters and I want to be able to seperate the string into parts. An example of the string looks like this FAP834E. I want to seperate it so that the first letter is seperate (F), the second and third are together (AP), … | |
Re: Whats wrong with this : [code] vector< vector<Point> > possible_neurons vector< vector<Point> > possible_neurons_second_copy; possible_neurons_second_copy = possible_neurons; [/code] | |
Re: Here is an example : [code] #include <iostream> #include <vector> #include <string> using namespace std; int main(){ vector< string > names; const string END = "!"; cout << "Enter many names... <enter '" << END << "' to quit >\n"; while(true){ string temp; cin >> temp; if(temp != END) names.push_back(temp); … | |
Re: >>I want to optimize the following small integer program in speed May I ask why? | |
Re: void* is usually used to simulate generics in C. In C++, template were made to remove this bad method. Since you are using C++, definitely, ditch void* and use templates. | |
Re: Also subtle but still there, this part : [code] char* argv[1] [/code] creates a array of char pointer, with size 1, thus only index 0 is valid. That means that this code :[code] string arg = argv[1]; [/code] is a index out of bounds. | |
Re: No that you have hardcoded the work, I would use stl to lessen the work I have to do. That means, more efficient code, safer, readability, and shorter code. For example, your listPropertiesSorted could be something like this : [code] bool propertiesCompare(const Property& lhs, const Property& rhs){ /* compare properties … | |
Re: I hope there is no naming conflict here , since there is a std::list. But this code: [code]listArray = new list[hashTableSize];[/code] will THROW and exception, instead of setting listArray to null. So there is no reason to check if listArray is null, because you won't get a chance to check … | |
Re: For this, read up on [URL="http://en.wikipedia.org/wiki/Modular_exponentiation"]Modular exponentiation[/URL]. Using that technique, will help you solve this problem. | |
Re: Not compiled. [code] #include <iostream> #include <fstream> #include <algorithm> #include <string> using namespace std; int main(){ std::ifstream fileReader("text.txt"); std::string content; std::string temp; while( getline(fileReader,temp) ){ content += temp; } char letterToFind = 'A'; int count = std::count(content.begin(),content.end(),letterToFind); cout << count << " occurrence of '" << letterToFind << "'\n"; } … | |
Re: Note there are explicit formulas for 2x2 and 3x3 matrix, see [URL="http://en.wikipedia.org/wiki/Invertible_matrix"] here [/URL] | |
Re: why [URL="http://www.cplusplus.com/reference/algorithm/next_permutation/"]yes[/URL] there is. | |
Re: >>is this correct or wrong? why? what if you wanted to add more cities, say 100 more. How much code do you think you would have to write ? Thus a good code, not only cares about its present status, it also cares about its future status as well. | |
Re: >> What kind of math do they use and how?? Every kind. From simple addition, to stokes equations, to rays to everything. | |
Re: [QUOTE=iamthwee;1239322]Which one? Transpose, adjoint, inverse, addition, identity, multiplication ...[/QUOTE] subtraction, LU factorization, elementary row operations, power, determinants ... | |
Re: >>typedef std::vector vector <class B> bVecArray is that supposed to be : [code] typedef std::vector< vector <class B> >bVecArray //or typedef std::vector<class B> bVecArray [/code] | |
Re: opengl does not have anything for printing a text. If you are using glut. Then you can use glutBitmapCharacter function. If not, then there are plenty of libs that prints fancy texts for you. Go ahead and google it. | |
Re: Why would anyone do this? Ouch my eyes. Use either std::for_each, BOOST_FOR_EACH, or even manually. | |
Re: No you are confusing yourself. This is what happens as pointed out : [code] A ob4 = (ob1.operaotr+(ob2)).operator+(ob3); [/code] But I think your problem is that this code : [code] A operator + (const A & ob){ return (num+ ob.num); } [/code] This code does NOT return a const object. … | |
Re: 1) Write code. 2) Write more code. 3) Read up on design patterns, whether it be wiki or whatever 4) goto 1 until comfortable 5) Now every time you write code, you can either : 5a) Finish the code, and the project ( depending on its size) then take a … | |
Re: When you change the array size, change the bounds on the for loop as well. Thats why you should use integer constants : [code] const int MAX_SIZE = 10; int inputArray[MAX_SIZE] = {0}; //initialize all elements to 0 for(int i = 0; i < MAX_SIZE; ++i){ cin >> inputArray[i]; } … | |
Re: Generally : [code] declare var v1 declare stringstream converter declare var2 v2 converter << v1 //put variable 1 into stream, whether it be int,long,string... converter >> v2 //convert var1, into int,long,float,string or whatever type var2 is. [/code] | |
Re: >> why Turbo C++ is still the dominant compiler in universities that still teach C++ [citation?] And, if you are using C++, then definitely use C++ containers. else if you are using C, then don't use C++ containers , lol. | |
![]() | Re: Use the property of sets. It only inserts elements that are unique. That means no same element will exist in the container. Do something like this. Note not compiled : [code] struct MyData{ //bunch of datas }; bool operator(const MyData& lhs, const MyData& rhs){ return true; } std::istream& operator >>(std::istream& … ![]() |
Re: The problem is you separate the definition of printVector. Your compiler can't handle defining a template function somewhere else than its declared file. So do this instead. [code] //myTools.h template<class Iterator> static void print(Iterator begin, Iterator end){ while(begin != end){ cout << *begin++ << " "; }; } [/code] Better … | |
Re: The sphere could probably be drawing over your polygons. But, i'll have to see your code first. | |
Re: >> don't I need to derefence Yes you do >>so the -> operator should be necessary on the first case Nope. The operator[] deferences the pointer. | |
Not exactly sure where I would have posted this, maybe in the help wanted section, if there is one,( sorry I didn't bother looking). But I feel like I should place this post here, because there are some smart people that lurks in these woods. So I have my first … | |
Re: Better yet, you should decouple the system. A player class should not have an array that stores the animation sequence. Try something like this for example. [code] class Player{ //blah blah blah void move(int x, int y){ /*logic goes here */ } //more blah blah blah }; template<typename CoordType> struct … | |
Its this side thing I was working one, when I got the chance. Its not very good right now, as its still in its developing stage. But its still ok, where I can show it of, lol. Attached is an exe, that given a set of data points, it tries … | |
Re: Also add std namespace : [code] #include<iostream.h> void hi(void); void name(void); using namespace std; int main() { ... } [/code] Otherwise you get errors like "cin" not found, and so on. | |
Re: [URL="http://en.wikipedia.org/wiki/Interpreter_pattern"]Wiki[/URL] is pretty clear. What part is confusing? Look at the [URL="http://upload.wikimedia.org/wikipedia/en/0/03/Interpreter_UML_class_diagram.jpg"]UML[/URL]diagram, and see if that helps. | |
Re: [QUOTE=spartanace;1232890]I found the solution just in case anyone is staring at this thread wondering the same thing about there template. The template is supposed to be a .h(header) rather than a .cpp.[/QUOTE] Yes thats, a known fact. The up coming C++0x is going to fix this. | |
Re: Create a hierarchy : [code] class Item{ //... virtual int points()const; //returns how much points this item is worth }; class Book{ //... int points()const{ return 2; } }; class Food{ //... int points()const{ return 5; } } ; //... [/code] | |
Re: If i read your question correctly then you can just do this : [code] int twoD[90][10]; //initialize twoD here int * randPtr = 0; int row = random(0,90); //some random function that returns a random number from [0,90) int col = random(0,10); randPtr = &twoD[row][col]; [/code] | |
Re: Which version of MS Wrod do you have. In version 2007, it saves the formatting and the colors. Perhaps, try copy/pasting it on a text file. And then export it on M.S word. | |
Re: Hey Narue, let me ask you something. If you got an offer to write a software, and your choices were only C and C++. Which would you choose ? "Different", yes. "Better", no" Can you show why this is ? Thats a big claim. I understand that OOP programming can … | |
Re: Can you explain a little more on what the problem is, and how you determine its a problem? |
The End.