2,712 Posted Topics

Member Avatar for mrnutty

This is a simple demonstration of meta programming. It shows the idea of meta programming. It basically calculates the factorial of a number before runtime. When I first saw the concept of meta programming, it blew my mind so badly. I was so surprised that one could do this. Its …

Member Avatar for griswolf
2
410
Member Avatar for Agni

Let me try to take a crack at this, after googling it. Its gonna be a long post, so I hope you are ready to read it. So first things first you know what inline functions are right? Just to recap, when you inline a function, you suggest to the …

Member Avatar for mrnutty
0
653
Member Avatar for usafsatwide

char is short for character, which means only 1 letter, not multiple. So doing this [i] char a = "huh" [/i] generates an error because a char variable can only point to one letter. To solve your problem replace char with std::string, in the return type as well as the …

Member Avatar for usafsatwide
0
264
Member Avatar for interist

I cant say for sure, but read them as ints; [code] int val = 0; while(file >> val){ cout << val << endl; } [/code]

Member Avatar for mrnutty
0
80
Member Avatar for mrnutty

How do I get over a break up? I am feeling really shitty. My ex girl who was my first just gave me the "we should be friends" card. Actually we been on and off lately because of some complicated stuff. But now, I don't want to go back, and …

Member Avatar for mrnutty
2
119
Member Avatar for saqib_604

[QUOTE=nbaztec;1275986]You should try looking into operator overloading: [CODE] int* operator >> (int *RHS) { RHS = this->array; return RHS; //For chaining } [/CODE][/QUOTE] Your operator overloading would allow this obscure code : [code] int * a = {1,2,3,4,5}; Integer num = Integer(a,5); num >>(a) [/code] which to me dosen't make …

Member Avatar for mrnutty
0
297
Member Avatar for musthafa.aj
Member Avatar for Dcurvez
0
97
Member Avatar for ika_fantasy00

Just another way, use stl::map; [code] #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main(){ std::map<string,int> dict; std::vector< pair<string,int> > vec; vec.push_back( make_pair("basketball",0)); vec.push_back( make_pair("soccer",0)); vec.push_back( make_pair("tennis",0)); vec.push_back( make_pair("football",0)); vec.push_back( make_pair("swimming",0)); dict.insert(vec.begin(),vec.end()); string input; cout << "Enter a sport and see if I have it\n<input>"; while(cin …

Member Avatar for ika_fantasy00
0
198
Member Avatar for HelloMe

>>I read that code reading will enormously boost your programming skills. Nope. It might help sometime, but to get better at programming you need to go program. Of course seeing someone else's code might trigger something in your brain for the better.

Member Avatar for TrustyTony
0
82
Member Avatar for mrnutty

Does browser treat "id" and "class" as the same, even though they have different meaning?

Member Avatar for rajarajan2017
0
130
Member Avatar for gretty

Get the input as a string and append those strings : [code] cout<<"Enter a hex number : "; string s1, s2; cin >> s1 >> s2; s1 += s2; cout<<s1; [/code]

Member Avatar for archana.c07
0
2K
Member Avatar for intills

whats with the c-style syntax? Use proper C++ syntax here, or else jump towards the C forum, where your kind are welcomed lol. [code] string input; while(cin >> input){ input[0] = toupper(input[0]); cout << input << endl; } [/code]

Member Avatar for mrnutty
0
255
Member Avatar for Awah Mohamed

>>Ultimately if you want to make programming a career then you will need a college degree Not necessarily, I know and heard of plenty of people that are doing really well without a degree. From what I have heard, a degree will really help get you that first job, afterwards …

Member Avatar for mrnutty
0
88
Member Avatar for aranjan

Since you are already using std::vector, why not use std::sort. All you have to do is define a compare function. [code] bool sortByExp(const poly& lhs,const poly& rhs){ return lhs.exp < rhs.exp; } //.... //somewhere in your code std::sort(a.begin(),a.end(),sortByExp); [/code]

Member Avatar for StuXYZ
0
153
Member Avatar for archana.c07

Try doing this : [code] int64 bigEndian(short* hex, int size){ if(size > 18 || size < 1) return -1; //int64 cannot hold anymore int64 res = int64(); for(int i = 0; i != size-1; ++i){ //OR and SHIFT as we go res |= hex[i]; res <<= 8; } //Just OR …

Member Avatar for mrnutty
0
176
Member Avatar for Dimesh

Just to repeat whats been said again. [i]int IntegerArray[5] = {0};[/i] [B]initializes all elements inside the array to 0.[/B] [i]int IntegerArray[5] = {0,0,0,0,0};[/i] [B]Here you are explicitly initializing each element to 0.[/B] [i]int IntegerArray[5] = {10,20,30,40,50};[/i] [B]Here you are explicitly giving each element inside the array a value. So IntegerArray[0] …

Member Avatar for Dimesh
-1
75
Member Avatar for Awah Mohamed

You can use an online compiler if you want. That way you can compile your code and such.

Member Avatar for Ancient Dragon
0
232
Member Avatar for hg_fs2002

@OP, why is your code so bad? I don't know what you need, but how about something like this : [code] string aLine; const int MAX_PRINT_CHAR = 80; getline(fileIn,aLine){ if(aLine.size() < MAX_PRINT_CHAR ) cout << aLine << endl; //else print the first MAX_PRINT_CHAR characters and then print the rest in …

Member Avatar for Ancient Dragon
0
94
Member Avatar for creative9k

You don't need while loop. IMO the forloop looks better and easier to read( most of the time).

Member Avatar for creative9k
0
146
Member Avatar for vbx_wx

>>What can i say about the results obtained with STL when implementin Data Structures Not sure if tat question makes sense. Do you mean, [I]What can I say about the results obtained, when using STL to implement a data structure?[/I] >>Future research about data tsructures using STL. Recommend books, papers, …

Member Avatar for mrnutty
0
204
Member Avatar for XxPKMNxX

Also this code, remember to use brackets to declare a block : [code] if(AdventureGame.keypressed[DIK_6]){ /* code goes here */ } [/code] Also I'm not sure if ur trying to optimize by this statement : [code] if (AdventureGame.keypressed[DIK_F] && (ignition == false)) ignition = true; if (AdventureGame.keypressed[DIK_G] && (ignition == true)) …

Member Avatar for mrnutty
0
112
Member Avatar for kunkunlol

Create a structure : [code] struct Player{ string name; int score; Player() : name(), score(){} }; [/code] Define an extraction operator, to extract into the struct : [code] std::istream& operator >>(std::istream& inFile, Player& p){ return inFile >> p.name >> p.score; } [/code] now create a vector of players : [code] …

Member Avatar for Excizted
0
104
Member Avatar for rakeshk_87

Remember, when defining a class, you should make that class objective minimal as possible. So don't dump all functions and variable into the class if not necessary.

Member Avatar for rakeshk_87
0
134
Member Avatar for Excizted

Why is Vector3::operator* returning a const Vector3 and not just a regular Vector3? Why does your Quanternion class contain a "x,y,z" variable, when you have Vector3 for that exact purpose? Unless, your using dynamic memory in Vector3, which I doubt, then I am doubting your debugging skills. What happens if …

Member Avatar for Excizted
0
196
Member Avatar for mrnutty

Download [URL="http://www.2shared.com/file/MGH_DXrx/lol.html"]this [/URL]great app, that I created. You will like it if you like basketball, especially.

Member Avatar for mrnutty
0
71
Member Avatar for Amoblaze
Member Avatar for shankarz
Member Avatar for papamutz

what you are looking for is [i] std::vector<string> [/i]. Here are some examples. [code] std::vector<string> v; v.push_back("hello"); v.push_back("goodbye"); cout << v[0] << endl; cout << v[1] << endl; [/code]

Member Avatar for mrnutty
0
35
Member Avatar for mark88211

Using strings, so concatenations will be easier ; [code] string firstName = "dani"; string lastName = "web"; string fullName = firstName + lastName; //concatenation string tmp = fullName; //reverse std::reverse(fullName.begin(),fullName.end()); if(fullName == tmp){ cout << "Palindrome\n"; } else cout << "Not Palindrome\n"; [/code]

Member Avatar for bagi.padhu
0
425
Member Avatar for scholar

You mean if g2 is a subgraph of g1? Or else, g2 is automatically a subgraph of g2. Well read [URL="http://www.engr.uconn.edu/~vkk06001/GraphIsomorphism/Papers/Ullman_Algorithm.pdf"]this[/URL] paper on the algorithm.

Member Avatar for mrnutty
0
72
Member Avatar for Codname47
Member Avatar for Angelaa
Member Avatar for Orion2k

1)ISO C++ does not support 'long long' 2)Use functions, it makes it easier and clearer 3)No need for system("pause"), either let the IDE handle that, or use better options 4)Rename your variable to something more appropriate. 5)Why 999999? Why do you limit it to that? Compare with this : [code]#include …

Member Avatar for mrnutty
0
120
Member Avatar for oneml
Member Avatar for Daqpan

@dusktreader: You can combine your convert code into 1 : [code] template<typename ReturnType, typename InputType> ReturnType convertTo(const InputType& in){ std::stringstream ss; ss << in; ReturnType ret = ReturnType(); if( (ss >> ret).fail()) throw std::exception("Conversion failed"); return ret; } int main(){ float pi = convertTo<float>("3.1415"); string strPi = convertTo<string>(pi); } [/code]

Member Avatar for dusktreader
0
135
Member Avatar for Member 784453

In little programs like your it doesn't show why its so bad. Just trust us, when we say do not use global variables. It leads to much complication, and ugly code. Compare your code with this non global variable one : [code] #include <iostream> using namespace std; int main(){ char …

Member Avatar for Member 784453
0
164
Member Avatar for intelfx

The easiest way to do this is use stl's, [URL="http://www.cplusplus.com/reference/algorithm/set_difference/"]set_difference[/URL].

Member Avatar for intelfx
0
3K
Member Avatar for dansnyderECE

Let me emphasis this : [QUOTE]How do I access reg in ExecutionFlow.cpp?[/QUOTE] Excitized: [B][U]You need access to the specific instance of ThreadContext[/U][/B]

Member Avatar for Excizted
0
183
Member Avatar for vbx_wx
Member Avatar for HAIDER69

Yes what does difference mean in your case ? difference1 : 4 - 3 = 1 difference2 : {a,b,c} - {a,d,f} = {b,c}

Member Avatar for HAIDER69
0
3K
Member Avatar for mebob
Member Avatar for mebob
0
111
Member Avatar for sisterjo

Ugh... [code] #include <iostream> #include <iomanip> #include <string> #include <fstream> #include <cstdlib> using namespace std; int main() { float totalTax = 0; // declare total tax = 0 float totalGrossEarnings =0; // declare total gross earnings = 0 float totalMedicalLevy = 0; // declare total medical levy = 0 float …

Member Avatar for mrnutty
0
187
Member Avatar for duuude

Wait how is boost timer supposed to help? He wants to time the input from the user.

Member Avatar for jonsca
0
208
Member Avatar for Member 784453

>>expression == true + true what caused you to think this is correct? What do you think it does?

Member Avatar for Member 784453
0
121
Member Avatar for rayborn66
Member Avatar for Kanoisa
0
232
Member Avatar for kunkunlol

That function is badly coded and harder to understand. I haven't tried it but this should work and easier to read : [code] //calls a helper function int sumLeafs(){ int sum = 0; _sumLeafs(getRoot(),sum); //_sumLeafs is a private helper function return sum; } //a node is a leaf, if it …

Member Avatar for mrnutty
0
152
Member Avatar for empror9

Why dont you do a test run and see if its correct for your self. Use your calculator to check if Question #1 is correct, and use the web to check if Question #2 is correct. I can't really tell you because your code is hard to read.

Member Avatar for NP-complete
0
98
Member Avatar for c++learner

>>I'm not sure how to create a function that accepts multiple arguments. Its easy, its very same as a single argument function. Compare these 2 functions. [code] void one(int a){ /* do something with a */} void two(int a, int b){ /* do something with a and b */ } …

Member Avatar for c++learner
0
154
Member Avatar for sarminatorius

Try this, write std::list<int> a, into your compiler, and right click it. See if there is an option that lets you "see deceleration or initialization". I doubt that you will find the code. Most of them are written into a dll, and the libraries aren't very easy to read. So …

Member Avatar for mrnutty
0
95
Member Avatar for Dimitar

>> I think that the one with pre-allocation should be faste First rookie mistake, pre-optimization! Forget about it using pre-allocation. Just do it without it. It will definitely be fast enough, unless you have some special case.

Member Avatar for Dimitar
0
435

The End.