2,712 Posted Topics
Re: [QUOTE=vijayan121;1299452]> Is there any way of checking all elements in a queue without calling pop(). Yes, if you have used a [icode]std::queue<T>[/icode] with the default [icode]std::deque<>[/icode] for the second template parameter. [CODE]template< typename T > void foobar( const std::queue<T>& queue ) { typename std::deque<T>::const_pointer begin = &queue.front() ; typename std::deque<T>::const_pointer … | |
Re: Why would you want to do this is beyond my feeble understanding. But is this the output you were thinking of? [code] #include <iostream> #include <string> #include <sstream> using namespace std; template<typename R, typename T> R castTo(const T& arg){ stringstream ss; ss << arg; R val = R(); ss >> … | |
Re: Memory in C++ fall into 3 category : [B]static memory [/B]: Memory is occupied until the end of the program [B]heap memory[/B]: Memory is occupied until freed [B]Stack memory [/B]: Memory is occupied until the end of the block, in which it was declared. Thats a very simple description. If … | |
Re: Does SuperClass have to be abstract? | |
Re: Instead of creating 2 function, maximum and second maximum, just create 1 function called sortArray. Then you can just get the maximum at element 0 or the last element, depending if you sort it descending or ascending. You can get the second,third,fourth... or whatever largest easy as well. | |
Re: >>[b]aDir.erase(found);[/b] Look at [URL="http://www.cplusplus.com/reference/string/string/erase/"]string.erase[/URL] function prototype. By that command, you are erasing all elements starting at the position found. What you need is this [b][i]aDir.erase(found,1); [/i][/b] | |
Re: Make your getName function a const corrected function like so : [code] string getName()const; //the const says that it will not change any member variable, presumably //.cpp string getName()const{ return name; } [/code] | |
Re: Also remember that cosine and sinus function takes in radians and not degrees. So this [code] circle.x = r*cos(i) - h; circle.y = r*sin(i) + k; [/code] should be this : [code] float rad = 3.14f/180.0f * i; circle.x = r*cos(rad) - h; circle.y = r*sin(rad) + k; [/code] | |
Re: You need to use wide char. Try this : [code] wchar_t *msg = L"Hello world"; wchar_t *title = L"Greeting"; MessageBox(hWnd,msg,title,MB_OK);[/code] | |
Re: Ughh. No thanks. I had enough discrete mathematics class at my school for my lifetime. Anyways, looks good. Keep it up. Might read it fully, when I got the time. | |
Re: >>i want it to end after a character is pressed. Use this : [code] vector<int> vec; int n = 0; //while user inputs a number, save it while(cin >> n){ vec.push_back(n); } //now reset the stream cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); //now carry on with your code [/code] | |
Re: >>I was wondering if it's possible to add for example the struct below into a binary tree: Yes it is. All you have to do is create a relational operator that compares hours as primary and minutes as secondary. Come to think of it. A priority_queue is the correct data … | |
Re: This compiles in visual studio 2008 express edition: [code] #include <iostream> using namespace std; int main(){ string name = "lol"; } [/code] | |
Re: What exactly are you trying to solve? Why do you need its hex values? Are you hashing? | |
Re: >>it[switch statements] doesn't make the slightest difference at the end On the contrary it does. Switch statements are easier to read, cleaner, and faster than ifs/else's. >>But, to be even more on the C++ side, you can use function objects And to be even more more towards C++ side, you … | |
Re: [QUOTE=rax_19;1295016]:cool: hi Friends,.,. !! i want to know a perfect time consumption for a given particular program.. [B][COLOR="red"]IN MILLISECONDs[/COLOR][/B] I know the way of using following method: [CODE=c] start=clock(); /*... ... my programming logic . . . ... */ end=clock(); difference=(end-start);[/CODE] But it gives time in seconds , which is … | |
Re: You need to pass the array as you suggested. Its the same as passing an array of ints, or whatever, its just a different type. For example : [code] int search(Inventory* items, int size){ /*code to search */ } void print(Iventory* items, int size){ /* code to print */ } … | |
Re: That code is kind of confusing if you do not know the meaning of i/j. Take i = 10 for example, and we want to see if 10 is a prime number. To do this, what your code does is run to all numbers from j = 2 to j … | |
Re: >>Is it possible to have pointers to references in c++ Yes its possible, long as you watch out for const. [code] #include <iostream> #include <cmath> using namespace std; int main() { int X = 4; int &y = X; int *p_to_y = &y; cout<<"X is " << X<<endl; cout<<"Y is … | |
Re: There is no way in C++, but you can do something like this : [code] void printN(char c, int n){ while(n--) cout << c; } int main(){ int a = 1, b = 2; const int ADJUSTMENT = 30; printN(' ',ADJUSTMENT); cout<<a<<" "<<"+ x = "<<b<<endl; } [/code] | |
Re: Is there a certain reason why you are doing this? What are you trying to solve? | |
Re: Make it more concise : [code] void InitializeBoard(char board[][3]){ board[0][0] = '1'; board[0][1] = '2'; board[0][2] = '3'; board[1][0] = '4'; board[1][1] = '5'; board[1][2] = '6'; board[2][0] = '7'; board[2][1] = '8'; board[2][2] = '9'; } [/code] is the same as [code] for(int r = 0;r != 3; ++r){ … | |
Re: [QUOTE=epoi;1293176]cant help u with this. I'm still at c program. sorry bro[/QUOTE] Then why bother posting? @OP, you have more than 1 issues with your code. But I'll let someone handle out the details. But to answer your question, you if statement should be : [code] //read as : "if … | |
Re: It works differently for char. It does not print the address, but it prints all characters that the pointer is pointing to, until it reaches a null character. | |
Re: [code] char ch = 0; //read file character by character while(file && file.get(ch) ){ cout << ch; } [/code] | |
Re: @OP: You should do something like this : [code] int main(){ Game game; while(game.isNotOver()){ int state = game.getState(); switch(state){ case PAUSE_GAME : pauseGame(game); break; case PLAY_GAME : playGame(game); break; case EXIT_GAME : cleanUp(game); break; } if(!game.isNotOver){ //if game is over bool playAgain = checkIfUserWantsToPlayAgain(); if(playAgain) game = Game(); //re-initialize everything … | |
Re: @OP: First work to get a O(n) solution to the maximum sum problem for a 1d array. And after you get that, use that to your advantage for this problem. At best, you will do O(n^3), if I'm not mistaken. | |
Re: 1) Easiest way, copy ALL of the data into notepad 2) On the notepad, click Edit->replace. Now replace all ',' with ' ' 3) Now you can read in the date as a string, and the price as a double | |
Re: Its undefined behavior because of there is no [URL="http://en.wikipedia.org/wiki/Sequence_point"]Sequence_point[/URL]. | |
Re: some hints : [code] char ch1 = 'a'; char ch2 = '#'; cout << isalpha( ch1 ) << endl; //true cout << isalpha( ch2 ) << endl; //false [/code] | |
Re: Ok, first how much of C++ concepts have you learned? In fact, to be more general how much of programming concepts have you learned? Any data structure training? Know what a [i] pure virtual base class destructor is ? [/i] Do you know when is the right time to use … | |
Re: First : Don't use pointers, as in don't do this [b][i]map<T1, T2>* myTempMap[/i][/b]. In C++ you would use reference : [b][i] map<T1, T2>& myTempMap [/i][/b]. That way you avoid doing stuff like (*myTempMap).blah(). Second your problem is comes from line 9, specifically this code : [code](*myTempMap).insert(ins_pair(10,"NewValueInserted"));[/code] The reason you get … | |
Re: [QUOTE=scar164;1290328]Yay, I got it too work, and no my function is exactly this. What I am doing is creating two functions for creating and coloring a triangle. ColorTriangle takes the array rgb and 3 numbers represting r, g and b values then CreateTriangle takes the rgb which has been modified … | |
Re: A couple result from googling, 1)[URL="http://old.nabble.com/g%2B%2B-4.3.2-linking-error---auto-import-td23149301.html"]uno[/URL] 2)[URL="http://forums.codeblocks.org/index.php?topic=12231.0"]duos[/URL]. | |
Re: [QUOTE=mike_2000_17;1289799]Don't let this blow your mind: [CODE] aReturnType some_function_name(aParameterType some_parameter, aReferencedType& some_ref_parameter) { aType some_variable(SOME_INITIAL_VALUE); for(anIterator some_iterator = some_start_value;some_iterator != some_end_value; ++some_iterator) some_variable += some_other_function_name(some_parameter, some_ref_parameter); return yet_another_function(some_variable); }; [/CODE] These are just phony names people use in text books to make examples (so is Foo and Bar, before you … | |
Re: [CODE]b = c/d [/CODE][CODE] b=(c)/(d++)[/CODE] The parathesis does not change what happens. It still reads from left to right. The post-increment operator returns d and then increments d. For example this is roughly what the post increment operator does: [code] temp = i; i = i + 1; return temp … | |
Re: Work backwards : [code] Data m1p1; Data m1p2; Data m1p3; Data m2p1; Data m2p2; Data* pointerToM1P1 = &m1p1; Data* pointerToM1P2 = &m1p2; Data* pointerToM1P3 = &m1p3; Data* pointerToM2P1 = &m2p1; Data* pointerToM2P2 = &m2p2; Data** pointer_to_a_pointer_that_points_at_m1p1 = &pointerToM1P1; Data** pointer_to_a_pointer_that_points_at_m1p2 = &pointerToM1P2; Data** pointer_to_a_pointer_that_points_at_m1p3 = &pointerToM1P3; Data** pointer_to_a_pointer_that_points_at_m2p1 = &pointerToM2P1; … | |
Re: @OP: There is simply no reason to do this. Why would you want to do this? | |
Re: and another one : [code] #include <iostream> #include <string> #include <algorithm> #include <numeric> #include <iterator> using namespace std; int main(){ string num; cin >> num; //print each digit std::copy( num.begin(), num.end(), std::ostream_iterator<char>(cout," ")); //get sum int sum = std::accumulate(num.begin(),num.end(),0) - '0' * num.size(); cout << "sum is = " << … ![]() | |
Re: Yes it is a problem. Each time you include that .h file, it will define a new static variable. | |
Re: So what you should do is, make more function, specifically these : [code] bool hasUpperCase(const char * str); //returns true if str has at least 1 upper case bool hasLowerCase(const char * str); //returns true if str has at least 1 lowercase bool hasDigit(const char * str);//returns true if str … | |
Re: First tell me what do you know about C++? And check out my sig. | |
Re: Short answer : Replace all string data type with int | |
| |
Re: When you compare your answer, make sure its in correct units, radians or degrees? >>so my first question, when i use the first fourmla, then how can i use the second one? The first and second formula has nothing to do in this case. The first formula shows one definition … | |
Re: No, use header files to define the skeleton of a class. And if possible, use .cpp file to define those classes. One of the main reason why one would do this is for organizations reasons. In some cases, having the definition in the .h file can lead to multiple definition … | |
Re: [URL="http://www2.research.att.com/~bs/applications.html"]List of software developed by C++[/URL] | |
Re: Why are you guys using void*, ewww on that. This is C++, use its power. |
The End.