15,300 Posted Topics
Re: use [b]ofstream[/b] instead of ostream. Then include <fstream> instead of <ostream>. Finally, add using statements after the include files [code] #include <fstream> using std::ofstream; using std::ifstream; // if you want this [/code] | |
Re: Here is how to round down [code] #include <iostream> #include <cmath> using std::cout; int main() { double n = 923.45; double intpart; double fractpart = modf(n/100, &intpart); cout << intpart * 100 << "\n"; return 0; } [/code] | |
Is it possible to allow members to edit the text that is highlighted in yellow, such as this one in a recent thread ? The OP (and me) are just SOL if he/she doesn't like the way it turned out. And Preview Post before submitting doesn't show it either. [quote] … | |
Re: try this: [icode]printf("%03d", num);[/icode] In "%03d", the 3 means minimum of 3 digits, 0 means print 0's if num is less than 3 digits. So num = 1, that will print 001 | |
Re: you can't because you can't stuff a whole string into a single character. If this is about some error message you got, then post the error message along with the code you wrote. | |
Re: Why are you using wchar_t ? Its a single character, not a string, so [icode]if(com = 'deldir.') {[/icode] isn't going to compile correctly. And [b]deldir[/b] isn't a single character either, so it should be in double quotes like any other normal string literal in C/C++, not single quotes. | |
Re: >>catch(std::char * s) Error most likely because there is no such thing as [b]std::char[/b]. change to this and retest: [icode]catch(const char* s)[/icode] | |
Re: Welcome to DaniWeb. >>I believe I must be the oldest member here! Not likely. See my public profile. And I know of at least one other member who is older than I am. So don't hesitate to post newbe type questions -- I still do that too. | |
Re: 1) prompt.h and prompt.cpp -- you need to specify function return values. 2) program is using uninitialized struct member in function Add_vcd(). You can fix that problem by adding a class constructor to the structure which initializes it. [code] struct vcdDB_T{ vcdRec_T vcdRecords[maxSize]; int vcdIndex; [color=red]public: vcdDB_T() {vcdIndex = 0;} … | |
Re: struct tm: is just a structure that can be use like any other structure. The localtime() function takes a time_t object and returns a pointer to a struct tm. [code] time_t now = time(0); // get current time struct tm* tm = localtime(&now); // get struct filled out cout << … | |
Re: post what you have tried. And post an example data file. | |
Re: I'm not sure what your program is attempting to do, but I do know it contains at least two memory leaks. You use [b]new[/b] operator to allocate memory to a Data pointer but never delete[] it before leaving the switch statement. | |
Re: line 61 (as shown in your post). You can not copy a character array into an int array. I guess same problem with the other lines that follow that one. line 60: >>if(factory_info[a].machine < factory_info[b].machine) You can't compare two C character arrays like that -- use strcmp() instead [icode]if( strcmp( … | |
Re: First, open the file in binary mode so that the os doesn't interpret the '\n' characters. Then you have to call seek() after each read operation. What you do with '\n' depends on what operating system you are using. *nix files just have '\n', but MS-Windolws uses '\r' and '\n', … | |
Re: I'm running on 64-bit Vista Home Premium, used VC++ 2008 Express, and your program ran ok for me both in IDE and command-line. After creating a win32 windows project I used all default values except changed from UNICODE to non-UNICODE. | |
Re: By tradition the two arguments to main() are declared as argc and argv -- you can name them anything you wish but custom dictates those two names [icode]int main(int argc, char* argv[]) [/icode] how do you know your program returns 1? The code you posted returns 0, not 1 (see … | |
Re: Work through the error messages one at a time. The first error is normally what's wrong. Correct that error then recompile -- you will get a lot fewer error messages that way. For example: line #2 of the code you posted is probably wrong. System header files are enclosed in … | |
Re: maybe yes, and maybe no. Depends on the code and what compiler it was written with. If written with Turbo C then probably won't work with VC++. | |
Re: [URL="http://en.wikipedia.org/wiki/Trackback"]google works wonders [/URL]:) | |
Re: Here is one way it could be done. [code] class example { public: int one; int two; }; int function1(int one, int two) { return one * two; } int function2(int one, int two) { return one + two; } int main() { example number; cout<<"enter numbers"<<endl; cin>>number.one>>number.two; cout << … | |
Re: or this using FILE* [code] char iobuf[255] = {0}; while( fgets(iobuf, sizeof(iobuf), pS) ) { fprintf(iobuf); } [/code] | |
Re: [QUOTE=Narue;710825]you can ask ten programmers to write the same program to the same specification and get ten completely different solutions.[/QUOTE] But only one correct solution -- mine :) | |
Re: I don't normally quote scripture, but can't help it this time: "Its easier for a camel to go through the eye of a needle than for a rich man to enter the kingdom of God." (Matthew 19:24) That means: I don't give a rats ass about all that much money. … | |
Re: The mod operator doesn't work on doubles -- only integers. And why is mph a double? Your program isn't even using the fractional parts so you might as well make it an integer and that will solve the problem for you. | |
Re: line 20 is in the wrong place -- move it down to line 25, when the variable search_item is known.\ [edit]^^^ he beat me to it :) [/edit] | |
Re: Welcome to DaniWeb. And yes, its about time you get off your a** and introduce yourself to us :) | |
Re: I guess you mean you want to know about the best compiler. On Vista that would be Visual C++ 2000 (Express). There are other compilers but IMO M$ VC++ 2008 Express is the best, mainly due to its excellent debugging facilities. Most any modern c++ compiler will compile c++ code … | |
Re: you need to initialize the values of i and j to something. | |
Re: [code] int main() { char answer; cout << "Do you feel sexy today?"; cin >> answer; if( answer != 'Y') return 0; // exit program // now do other things } [/code] | |
Re: The error on line 23 says variable i has not been declared. The reason is that you have to use { and } braces in the loop starting at line 19. | |
Re: start by using [URL="http://www.google.com/search?hl=en&q=c%2B%2B+stacks+tutorial&aq=f&oq="]google like this[/URL] (see the search bar at that link) | |
Re: First call [URL="http://msdn.microsoft.com/en-us/library/ms633585(VS.85).aspx"]GetWindowLongPtr[/URL] to get a pointer to its defaultProc then call CallWindowProc() when appropriate. See the GWLP_WNDPROC option. | |
Re: Are you combining client and server into just one program ? Or are they still two separate programs that are executed on the same machine ? >>Also how do i set a static ip address in the code because the Winsock Server requires the user to type an ip address … | |
Re: you can't insert strings into int arrays, but you can insert a character [icode]pointer[a][b] = '*';[/icode] <<< single quotes, not double quotes | |
Re: [QUOTE=sneekula;683008]Typical official communications between Canadians and their neighbours to the South. Americans: "Please divert your course 15 degrees to the north to avoid a collision." Canadians: "Recommend you divert YOUR course 15 degrees to the south to avoid a collision." Americans: "This is the captain of a US Navy ship. … | |
![]() | Re: line 39 is missing close parentheses -- ) Also you need to typecast total and sum to float to prevent loss of precision. line 6: you are using uninitialized variables Your program would run a bit better (faster and efficiently) if you used [b]else if[/b]. |
Re: You posted your assignment, now what do you parts don't you understand. | |
Re: google for the exact error message. Often google comes up with the answer. I recall seeing something about that problem before, but you didn't post the exact error message so I can't help you. BTW: The express edition doesn't do deployments -- you will have to do it manually or … | |
Re: I'm not supprised that produces a core dump. line 10 declared a pointer that points to nowhere -- there is no memory allocated to it. If x is supposed to be an array then use malloc() to allocate memory for the array [icode]x = malloc(10 * sizeof(int));[/icode] will allocate an … | |
| |
Re: First you have to allocate memory for ebase -- you are dereferencing an unallocated pointer. So the best you can do with that is [icode]ebase = *iter;[/icode] | |
Re: That is a *nix file -- if you are compiling for MS-Windows of some other os then you can't use it. | |
Re: Don't keep the numbers as a string, but as four integers. You could enter the values in the array in sorted order but that might be a bit more difficult. [icode]int numbers[4] = {0};[/icode] After they are entered then code a sort algorithm to sort them. Or you | |
Re: you have to pass fstream objects by reference [code] void initBoard([color=red]ifstream& [/color]board){ string squares; getline (board, squares, '\n'); cout << squares;}<------------ For testing purposes, will do other stuff l8r [/code] | |
Re: See the first three answers to [URL="http://www.daniweb.com/forums/post695854.html#post695854"]your other thread here.[/URL] | |
Re: how about a [URL="http://msdn.microsoft.com/en-us/library/aa579858(EXCHG.80).aspx"]managed tree view [/URL] | |
Re: Here is an example of how you could do that [code] int main() { char origstring[] = "Once upon a time there were three little pigs."; char StringToReplace[] = "were three little pigs"; char ReplaceString[] = " was a big bad wolf."; char* ptr = strstr(origstring, StringToReplace); if( ptr != … | |
Re: [QUOTE=skatamatic;703589]My price is set at $250.00[/QUOTE] You work cheap :) | |
Re: >>Structure doesn't have restricted acces In c++ they do -- structures are nearly identical to c++ classes, except the default access type is public. TMK there are no other differences between a structure and a class. |
The End.