166 Posted Topics
Re: MSVC, code::blocks, all the rest of the normal IDEs, etc. Pretty much just google "C++ IDE", and take your pick at random if you have no preference. I use MSVC 2008. | |
Re: Float is to short What double is to long A float stores 1/2 the bits of a double A double is a 64bit number, a float is 32bits like an int, but some of its storage is used for the decimal point. Use double, although with a number as small … | |
Re: If minutes < 10 std::cout << "0" ??? | |
Re: Make a function that blocks until year_seconds seconds have passed, where year_seconds is a variable you have flow control of, such that you can increase or decrease it at different phases of the evolution simulator you are creating. Naturally, the process will typically finish in microseconds, so if you want … | |
Re: [CODE] using namespace std; // don't const double Pi = 3.1415; // why not 3.1416 (3.14159) [/CODE] [CODE] int main() { master z01; double r; std::cout << "Please Enter A Radius \n"; std::cin >> r; z01.setvalue(r); // setvalue is really ambiguous, consider changing function name std::cout << "The area is: … | |
Re: So do you have a specific question or are you asking for me to do your homework for you? | |
Re: [CODE] default: "Illegal option!"; // Did you forget std::cout? This obviously won't compile [/CODE] | |
Re: [CODE] int hours(minutes/60); if( (minutes%60) > 0 ) ++hours; [/CODE] Divide minutes by 60 for the number of hours, the conversion to the "int" type will floor the value (drop any decimal amount) The % (modulus) operator returns a remainder of division. If your number of minutes is not divisible … | |
Re: What scope of reverse? Each line? Each character? Start by saving each line in an array of std::string, then iterate backward through that array. If it has to be by character, you could add a reverse printing of each std::string by the same method. If you want more help, at … | |
Re: How is this a stack? Do you just want to print a linked list? | |
Re: Edit: My bad, I just re-read the code. A fibonacci sequence starts with 0 for a reason, you omitted it. Also, you print starting from a[2] (fN=2) [CODE] cout << a[0] << "\n" << a[1] << "\n"; for(fN=2;fN<=i;++fN) { // note that because fN starts at 2, the range from … | |
Re: ...seriously? At least make the smallest attempt to accomplish your goal. Write at least 100 lines of code and return only after that, with a specific question about why you are stuck. How do you expect to learn if you're spoonfed your answers from start to finish? Besides, programming is … | |
Re: [CODE] int* getElements(int num) { // don't return "int" unless you cast to pointer later int *ptr; // this is a pointer to int ptr = new int[num]; // it is still a pointer to int, since the new array is of ints //Enter 5 numbers. std::cout << "Enter " … | |
Re: Modify your for loop according to the values of n you want to iterate. for numbers ranging from 10 to 10000: [CODE] for( i=10; i<10001; ++i ) { } [/CODE] would work just fine, so what's missing? [CODE] for( i=start; i<end+1; ++i ) { } [/CODE] just accept start and … | |
Re: q0[0] is an address + 0x00 (a base address, really), and what it points to is just an int. An int does not have enough space for 10 ints. You'll need to memcpy if you actually want to copy the data. Though, I'm not sure my solution is what the … | |
Re: For std::string, I'd do it this way: [CODE] // case insensitive string compare function int compare_string(const std::string & s1, const std::string& s2) { std::string::const_iterator it1=s1.begin(); std::string::const_iterator it2=s2.begin(); size_t size1=s1.size(), size2=s2.size();// cache lengths //return -1 or 1 according to strings' lengths if (size1!=size2) return (size1<size2) ? -1 : 1; //stop when … | |
Re: You might be interested in std::fstream, but do whatever way is easiest for you. | |
Re: [CODE] void bookInput::displaybook() { cout<< "\tName:"<< title << " \t\t\tDate Published: " << date<< endl; } [/CODE] Why are you only inserting tabs? Maybe it only goes to a newline because it ran out of space on the right side. Just insert a newline if you want a new line. … | |
Re: I know this is a C++ forum, but why don't you just do this in Ruby? Otherwise, make a thread that sleeps for 60 seconds and increments a counter by 1, when the counter is 120 (2 hours), reset it to 0 and execute the file read. Save the file … | |
Re: Powers of 10? Assuming you want a decimal representation. You'll have to define 'digit', due to this ambiguity. 0xFF vs 255, 2 'digits' vs 3 | |
Re: You can easily do it with a for loop, or any method of iteration. You could also track that information as soon as it is input, so that no iteration is necessary. (update average and total number) If you want more help than that, you'll have to post some of … | |
Re: I'm not really sure what you think the code you have means, but to me it is a little bit silly. [CODE] void mystring::reserve(size_t n) { if(!n>buf_size) return; char *swap = new char[n]; // also it's better to use powers of 2 to prevent overhead memcpy(swap,ptr_buffer,buf_size); // copy the old … | |
Re: I really don't think what you want here is a switch, it would make sense in the ruby language, but C/C++ switch statements only accept constants: [CODE] switch( sum ) { case 100: case 99: // ... // yes you have to write them all case 96: letter='A'; break; case … | |
Re: PlaySound("file.wav",NULL,SND_FILENAME|SND_ASYNC); Note the flag SND_ASYNC, which means that the file will play asynchronously during process execution (it won't block). So if you set this flag, it will play the file without 'pausing' | |
Re: instead of using parameters like this: int foo( int min, int max ); why not: [CODE] int range_rand( int a, int b ) { int high, low; (a<=b)?(low=a,high=b):(low=b,high=a); int ans=rand()%high; // I'm assuming you seeded rand already if( ans < low ) ans+=low; // this won't actually work if your … | |
Re: Rather than predefining your array a[], why not use the integer value of n as the final output? I don't like that you didn't post any code, but here's a hint: [CODE] for( i=0;i<n; ++i ) { a[i] = i+1; std::cout << a[i] << " "; } [/CODE] | |
Re: word.at(i) = test.at(j); [B]compare to:[/B] word.at( i ) = word.at( j ); // did you really want to write into what you're copying from? As for your warning: j = ( word.size() -1 ); j is an int, size() returns a size_t, which is an unsigned int In this case, … | |
Re: @sanchar MSVC (MicroSoft Visual Studio) is just an IDE/compiler, "Visual C++" -is- C++, though I wouldn't say with [B]complete[/B] certainty that it is 100% standards compliant, I think for your purposes it is effectively the same as "C++" MSVC comes with a resource creator (for drag and drop creation of … | |
Re: [CODE] while (num == 0) { cout << "Type in two values:\n"; cin >> num; // num isn't 0 if you enter anything but 0, no more while loop. [/CODE] You said "keep looping", obviously it won't loop if num isn't 0 If you want it to loop forever, try … | |
Re: [CODE] // use a template class template <typename T, typename T2> class DataCompare { public: // you can probably do this better, I just directly modified your example // It probably won't suit your needs, etc etc, might have typos bool operator()(const T& el1, const T& el2) const { return … | |
Re: [CODE] cmptr pc[1]=pc[0]; // this is a redefinition pc[1] = pc[0]; // this is what you actually wanted, assuming a was at least 2 cmptr *pc = new cmptr[100]; // this would be a = 100 pc[0].defaultinfo(); // both totally ok pc[99].defaultinfo(); // both totally ok // pc is a … | |
Re: char[25] can only hold '1' string of 25 character length, each character is 1 byte of data (char) for example, this isn't dynamic or anything, but if you did this: char[25][15] you could store 25 names, which are up to 15 characters long name[i] will be able to hold only … | |
Re: double array[r][1]; <--- r is 0, so this is the same as writing: [B]double array[0][1];[/B] You then go on to increment r: for(int r=0;r<20;r++) { and try to write out of array bounds: array[r][0] = tf; but the array only goes up to array[0], not array[1]. | |
Re: std::stringstream std::fstream vs std::ostringstream std::ofstream std::ifstream etc... Edit: It seems I misunderstood your post, my apologies. Personally, I'd do it the C way, because it would be easier for me. That's just my taste though, you should do whatever is easiest for you. | |
Re: std::map<std::string,dvd> car_info; std::map will sort this array automatically based on the < operator for std::string std::map["volvo"] = dvd(constructor values); // or whatever temporary dvd you make | |
Re: Your problem is more related to the reason the limit system is a fundamental concept in calculus. How many square sides do you need to create a perfect circle? In this case, it's 1 per pixel. How is that any less taxing than using a single trig function for each … | |
![]() | Re: last=MAX_UNSIGNED_INT? Sounds like you subtracted 1 from 0, as there are not that many words in a dictionary. |
Re: Hint: substr() and find() | |
Re: Use the logical OR operator, which is "||" instead of "&&" "&&" is the AND operator (TRUE && FALSE && TRUE) evaluates to (FALSE) (TRUE || FALSE || TRUE) evaluates to (TRUE) [B]Edit: A poster above me already mentioned this, but you should probably read up on the logical operators … | |
Re: [B]Edit: You should remember that error message specifically, because it is a misleading one for less experienced programmers.[/B] [CODE] struct attrib{ char x; int y; char cont; }; // <-- you didn't have a trailing semicolon attrib brd[8][8]; //ERROR WAS HERE <-- no it wasn't [/CODE] | |
![]() | Re: To access a single member of a string, it's typically safer to call string::at(), as it checks that the value passed to at() is in range. substr() seems really round-about for getting just one character. std::string[] or std::string.at() are much better solutions for your problem In terms of processing an … ![]() |
Re: Why not save each line as a string (whichever flavor you prefer), put those into any container/array, and then count them from there? You could easily do it with a multimap<std::string,int> for example, where int is incremented for each equivalent std::string, or set to 1 if the element did not … | |
Re: [B]Edit: Clarification. 'When' you call getLeafCount(node->right), is the stack value of 'node' the same as when the function began at first? Short answer: No[/B] [CODE] int getLeafCount(struct node* node, int count) { int temp = 0; if(node!=NULL) { if((node -> data %2) != 0) { temp++; count = count + … | |
Re: Operators are just functions, the reason you cannot pass () and [] as the same argument is that they are not necessarily the same function, they have different memory addresses and associated methodology. Rather, why not just overload your function? [CODE] void foo( int a ) { ; } void … | |
Re: CreateThread() Main is just the primary thread. [B]Edit:[/B] There are many implementations of createthread, and variations (such as createthreadex), an example implementation of createthread which might make your life easier is boost::thread | |
Re: Poster above you was correct, please look at how this is different from what you did. [CODE] class myplayclass { public: int x; int y; vector<int> myVofInt2; myplayclass() : myVofInt2(10) {} // you can call its constructor like this ~myplayclass(){} myplayclass(int intX):x(intX), myVofInt2(10) {y=0;} }; int _tmain(int argc, _TCHAR* argv[]) … | |
Re: I'm not sure I believe you, but if you aren't sure where to start, you could start by reading the documentation on std::fstream If you aren't allowed to use STL in your homework, read about these functions instead: fscanf() fgets() fgetc() fread() Good luck! If you want more help you'll … | |
Re: if(file.is_open()) // is a good place to start Mind you, you may just not have enough RAM, especially with windows XP, to deal with a heap allocation of 1.5GB Programs such as 7zip, which unzip files of greater sizes in XP, do so with partial reading, intermediary files, or any … | |
Re: cout << line[count] // <--- you are returning uninitialized data, as the variable count can be greater than the size of your input. |
The End.