2,712 Posted Topics
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 … | |
Re: 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 … | |
Re: 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 … | |
Re: I cant say for sure, but read them as ints; [code] int val = 0; while(file >> val){ cout << val << endl; } [/code] | |
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 … | |
Re: [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 … | |
Re: 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 … | |
Re: >>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. | |
Does browser treat "id" and "class" as the same, even though they have different meaning? ![]() | |
Re: 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] | |
Re: 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] | |
Re: >>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 … | |
Re: 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] | |
Re: 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 … | |
Re: 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] … | |
Re: You can use an online compiler if you want. That way you can compile your code and such. | |
Re: @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 … | |
Re: You don't need while loop. IMO the forloop looks better and easier to read( most of the time). | |
Re: >>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, … | |
Re: 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)) … | |
Re: 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] … | |
Re: 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. | |
Re: 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 … | |
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. | |
Re: [URL="http://lmgtfy.com/?q=assert+C"]hmmmmm....[/URL] | |
Re: 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] | |
Re: 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] | |
Re: 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. | |
| |
| |
Re: 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 … | |
Re: >>[B]while(counter<=SIZE)[/B] check that one again | |
Re: @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] | |
Re: 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 … | |
Re: The easiest way to do this is use stl's, [URL="http://www.cplusplus.com/reference/algorithm/set_difference/"]set_difference[/URL]. | |
Re: 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] | |
Re: Yes what does difference mean in your case ? difference1 : 4 - 3 = 1 difference2 : {a,b,c} - {a,d,f} = {b,c} | |
Re: Can you show me what a[] contains? It is probably an overflow problem. | |
Re: 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 … | |
Re: Wait how is boost timer supposed to help? He wants to time the input from the user. | |
Re: >>expression == true + true what caused you to think this is correct? What do you think it does? | |
Re: You do not account for the second "fin >> next" in your second code. | |
Re: 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 … | |
Re: 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. | |
Re: >>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 */ } … | |
Re: 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 … | |
Re: >> 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. |
The End.