2,712 Posted Topics

Member Avatar for posche
Member Avatar for drjay1627

[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 …

Member Avatar for vijayan121
0
129
Member Avatar for rtllz

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 >> …

Member Avatar for mrnutty
0
125
Member Avatar for qqwushi12345

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 …

Member Avatar for mrnutty
0
64
Member Avatar for bleedi
Member Avatar for gaurav_13191

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.

Member Avatar for gaurav_13191
0
102
Member Avatar for r14r

>>[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]

Member Avatar for sundip
0
118
Member Avatar for sbrohee

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]

Member Avatar for sbrohee
0
271
Member Avatar for ticktock

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]

Member Avatar for ticktock
0
315
Member Avatar for PixelExchange

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]

Member Avatar for PixelExchange
0
175
Member Avatar for AuburnMathTutor

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.

Member Avatar for AuburnMathTutor
-1
184
Member Avatar for Anyzen

>>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]

Member Avatar for Anyzen
0
104
Member Avatar for Drakarus

>>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 …

Member Avatar for Drakarus
0
281
Member Avatar for racoon8995

This compiles in visual studio 2008 express edition: [code] #include <iostream> using namespace std; int main(){ string name = "lol"; } [/code]

Member Avatar for vijayan121
0
173
Member Avatar for dansnyderECE

What exactly are you trying to solve? Why do you need its hex values? Are you hashing?

Member Avatar for vijayan121
0
220
Member Avatar for ftl25

>>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 …

Member Avatar for mike_2000_17
0
181
Member Avatar for rax_19

[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 …

Member Avatar for rax_19
0
298
Member Avatar for rObOtcOmpute

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 */ } …

Member Avatar for rObOtcOmpute
0
224
Member Avatar for literal

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 …

Member Avatar for literal
0
114
Member Avatar for Kusanagi03
Member Avatar for atch

>>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 …

Member Avatar for atch
-1
289
Member Avatar for aaronmk2

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]

Member Avatar for Nick Evan
0
170
Member Avatar for Anex
Member Avatar for Ancient Dragon
0
9K
Member Avatar for Haxifix

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){ …

Member Avatar for mrnutty
0
151
Member Avatar for sudoku43

[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 …

Member Avatar for RogueEffect
0
168
Member Avatar for liompa

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.

Member Avatar for mike_2000_17
0
76
Member Avatar for mrkaran

[code] char ch = 0; //read file character by character while(file && file.get(ch) ){ cout << ch; } [/code]

Member Avatar for mrkaran
0
99
Member Avatar for ssmg

@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 …

Member Avatar for ssmg
1
12K
Member Avatar for eman 22

@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.

Member Avatar for AuburnMathTutor
0
575
Member Avatar for dogwood705

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

Member Avatar for dogwood705
0
363
Member Avatar for vidyasmani

Its undefined behavior because of there is no [URL="http://en.wikipedia.org/wiki/Sequence_point"]Sequence_point[/URL].

Member Avatar for arkoenig
0
106
Member Avatar for gahhon

some hints : [code] char ch1 = 'a'; char ch2 = '#'; cout << isalpha( ch1 ) << endl; //true cout << isalpha( ch2 ) << endl; //false [/code]

Member Avatar for gahhon
0
152
Member Avatar for rootchord

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 …

Member Avatar for aslamnandyal
0
188
Member Avatar for old_jefrey

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 …

Member Avatar for mrnutty
0
106
Member Avatar for scar164

[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 …

Member Avatar for mrnutty
0
220
Member Avatar for tundra010

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].

Member Avatar for tundra010
0
131
Member Avatar for elsiekins

[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 …

Member Avatar for mrnutty
0
98
Member Avatar for daudiam

[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 …

Member Avatar for daudiam
0
242
Member Avatar for westony

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; …

Member Avatar for kings_mitra
0
88
Member Avatar for angelinrajeesha
Member Avatar for mrnutty
0
127
Member Avatar for ShadowOfBlood

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 = " << …

Member Avatar for 1stDAN
0
4K
Member Avatar for tennis

Yes it is a problem. Each time you include that .h file, it will define a new static variable.

Member Avatar for Nick Evan
0
88
Member Avatar for bmos

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 …

Member Avatar for Anyzen
0
6K
Member Avatar for Luther von Wulf
Member Avatar for mrnutty
-1
2K
Member Avatar for rowley4
Member Avatar for boos800
Member Avatar for empror9

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 …

Member Avatar for mike_2000_17
0
5K
Member Avatar for johnnyturbo3

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 …

Member Avatar for mike_2000_17
0
7K
Member Avatar for Nulled

[URL="http://www2.research.att.com/~bs/applications.html"]List of software developed by C++[/URL]

Member Avatar for Yojimbo_Beta
0
230
Member Avatar for renar
Member Avatar for Ancient Dragon
0
261

The End.