2,712 Posted Topics
Re: You need to create your own semi-string class, that has the operators above overloaded. | |
| |
![]() | |
| |
Re: Can you use pointers and dynamic memory? | |
Re: You can use the indexes, but you can also use flags. First try to read in a file. Then check for the first quote ( " ) and if found read in the data until another quote ( " ) is found. | |
Re: It alls here : [code] { switch (choice) { case 'a': case 'A': cout << "You are accelerating the car. "; cout << Accelerate(first) << endl; break; case 'b': case 'B': cout << "You have choosen to push the brake."; cout << Brake(first) << endl; break; } }while (toupper(choice) != … | |
Re: 1st tooo much common sense comment : second ; [code] while (num != 0) { digit= num%=10; // you are setting digit to the last number of 10 each time this loop runs. So you end up with a 1 digit number num/=10; } [/code] To reverse the number first … | |
Re: If not defined the compiler create a : default constructor like so someClass() { }, that does nothing default destructor like so ~someClass() {}, that does nothing default assignment operator default copy constructor default address operator | |
Re: also in c++, its #include< fstream> and not fstream.h | |
Re: vector<vector<char>> vset; //that should be an error because of the confusion of the stream operator >>. Need space between them. | |
Re: "(1) how to capture number of occurrences of 3 between 1 to 100? " Like this : 3,13,23,33,43,54,63,73,83,93 ? | |
Re: create a vectors of char*, then in a for loop, have char* pointing to a different vectors. | |
Re: You don't need a copy constructor for that. Only if you are using dynamic memory, then you will need a copy constructor. The std::string is it self dynamic and thus you don't have to keep track of heap memory for it, the stl does it for you. | |
Re: Here is a comment on the comments (just a few): input qty // get input from user, by creating a new variable and cin >>variable while qty > 0 //start a loop, with the conditional statement being while qty > 0 input size// ask user to input, same as step … | |
Re: Just don't use Hungarian. I use Camel naming convention like so , float PlayerLife | |
Re: 1) Ask user if he wants a seat, if so then 2) Check if there are seats to fill 3) If full, then give an error, else 4) get any random seat from the list of unfilled seat array | |
| |
Re: What do you mean. Something like this : static int Array[5] = {1,2,3,4,5}; | |
Re: to put code tags, do this : code */code , except delete * and leave no space in between. | |
Re: if you don't want to get the user's input as a string you can do the following (not tested) : [code] int num = 0; cout<<"Number please : "; cin >> num; while(!cin)//if input fails { cin.clear(); while(cin.get() != '\n') continue; cout<<"\nInvalid Input\n"; cout<<"Try again : "; cin >> num; … | |
Re: [QUOTE=TheSamwise;939520]Simply use "srand()" at the start of the program.[/QUOTE] srand() takes an argument. | |
Re: just make your own strcpy. Its not hard [code] //copy string 2 into string 1 bool stringCopy(std::string* str1, std::string* str2) { if(!str2[0]) return false; for(int i = 0; i < str2.size; i++) str1[i] = str2[i]; return true; } [/code] | |
Re: On the other hand, if you use new to allocate memory for the array then you should use delete [] array, syntax. And set the other pointers associated with the array to null. Also Why are you doing this : [code] double *pd = new (a + 5) double; [/code] … | |
Re: I would if I was at school right now, but sorry I am in my summer vacation :) | |
![]() | Re: If your using c++ , the command cout<<"\a"; makes a beep. You can be creative. If you are using windows, you can use beep(...), and adjust the frequency and the length of the tone. You can be creative. ![]() |
Re: Create an array[SIZE]; From 'i' to 'SIZE' store 'i' into array. shuffle array; extract info from array into new one, without the same index repeating. | |
Re: use seekg to set the position of the pointer to the beginning after its been read. [URL="http://www.cplusplus.com/reference/iostream/istream/seekg/"]http://www.cplusplus.com/reference/iostream/istream/seekg/[/URL] | |
Re: looking at your .txt file, you have the row and column backwards in declaring your tmp array variable. | |
Re: You can encrypt the text file just as you would encrypt a string. 1) Use a string to read in all data inside the ifstream 2) Use that string to encrypt it self , for example you can use key number to encrypt like so : [code] cout<<"Enter a key … | |
Re: This is how to do inheritance`: [code] class BankAccount { ... } //base class class Savings : pubilc BankAccount { ... } //saving derives from base class Checking : public BankAccount { ... } //checking derives from base class CD : public BankAccount { ...} [/code] The interface of BankAccount … | |
Re: Why would you want to do that? how about cout the expression manually? | |
Re: use the std::sort algo. you will need to give it your compare function which should compare the x first then the y. example : [code] #include<iostream> #include<vector> #include<algorithm> using std::vector; using std::cout; using std::cin; using std::endl; int main() { vector< vector<float> > vec2d(2,vector<float>(2,0)); for(int i =0; i < vec2d.size(); i++) … | |
Re: [code] //Are used to determine if certain settings are enabled/disabled //0->disabled //1->enabled "static int useRGB = 1; static int useLighting = 1; static int useFog = 0; static int useDB = 1; static int useLogo = 0; static int useQuads = 1;" //used for delay static int tick = -1; … | |
Re: I would suggest the following : 1) create an abstract base class that has the similar properties for all class 2) Derive a base class from the abstract, maybe a CarType class 3) Derive a Toyota, Honda, Lexus ... from CarType | |
Re: could you explain your problem. also note that in c++ use should use cmath instead of math.h. And forget about system(...) command. They are BAD. | |
Re: How about you dive into it and tells us if your stuck. Make some classes, like level, character, food ... so on from there | |
Re: [code] ifstream iFile("text.txt"); //open file /****/ whlie(!(iFile.eof() || iFile) //while there is stuff to read { // Read content. } [/code] | |
| |
Re: I think your template deceleration should look something like this : [code] template<typename Type1,typename Cont = vectors<int> > class Stack { ... } [/code] | |
Re: [code] sample s; //default ctor or if is provided then it is called sample s1(s); //copy ctor is called sample s2 = s1 ; //could use both copy ctor and assignment or just one. sample s3; s3 = s2; //use the assignment operator sample s4( 5, "string") ; //use the … | |
Re: Use [ code] [ /code] tags. You are missing a the while part in your do while loop. Using goto will get you killed (not really) in the c++ community. | |
Re: Here is an example : [code] int howMany = 0; cin >> howMany; for(int i = 0; i < 100; i ++) if(i % howMany == 0) cout << i; [/code] | |
Re: make inner public. Then in you can access it by the scope resolution operator like so outter::inner variable name; [edit] The above assumes "outside " means from outside of the class. | |
Re: You do know that your array is of size 0 in this code : [code] string pic_array[pic_count]; string used_pics[usedPic_count]; [/code] for your read function, use char *filename | |
Re: when you say "put it", do you mean you copy the whole function and redefine it in main? | |
Re: which part of overloading the << operator are you having trouble with? your prototype could be something like this : [code] std::ostream& operator<<(std::ostream& os, Real<T>& real); [/code] |
The End.