15,300 Posted Topics
Re: [QUOTE=andy257]Can c++ make programs that you can install onto a computer like you would software you buy from a shop. Basically does it allow you to make the installer setup stuff. Even if you program is very very basic. Is there software that does this for you and you just … | |
Re: my company forbids use of goto, and it is strictly enforced during peer review. Yes, programmers are NOT free to just code any way they wish -- there are coding standards and the code is periodically reviewed to insure those standards are followed. There is absolutely never justification for its … | |
Re: It is indeed a parameter passing technique -- there are only two ways to pass something, by value and by reference. Pass by reference can be done in one of two ways -- a pointer (C) or reference operator (C++). The three differences I can think of 1. use of … | |
Re: how to do that depends on the operating system. You can either use operating system-specific GUI drawing functions, or some SDK such as QT that is mostly os-independent. Either way, it will take several months to learn. There are some commercial graph packages you can buy -- some may even … | |
Re: get rid of that silly semicolon ';' at the end of the if statement. The next line, print(...) need a semicolon at the end. | |
Re: [QUOTE=123abc]That is definitely NOT me. It may be someone from my same class.[/QUOTE] read that other thread and use the same suggestions. Or do you want somebody to do your work for you? | |
Re: you are attempting to declare a function CalcDepr() within another function main(). You can't to that. Move all the code for CalcDepr() outside function main() and it will probably compile ok, unless of course there are other errors. [edit]Nevermind -- Narue answered your question. Too bad we can't delete our … | |
Re: the parameter to free() must be the same pointer that was returned by malloc(), calloc() or realloc(). Your program destroyed that pointer in the printf() statement. Why don't you use array a just like any other array instead of using pointer arithemic [code] for (i=0; i<SIZE; i++) a[i] = i … | |
Re: Well, it has nothing at all to do with MFC. You probably created a console application and tried to code a MS-Windows win32 api application. You will probably have to start all over and create the correct type of application (win32 application). | |
Re: double quotes mean a null-terminated string, single quotes is a single character. Replace the double quotes in the if statement to single quotes. [code] if ( term1[1] == '(' ) [/code] | |
Re: if you know the format, then its pretty easy [code] string date = "01/02/2005"; // 1 Feb 2005 int month = atoi(date.substr(3,2).c_str()); // do day and year similar to above [/code] | |
Re: [QUOTE=Narue] that still doesn't guarantee that your system is 32-bit. ;)[/QUOTE] Actually, it says nothing at all about the system. I have a new 64-bit system and sizeof(int) is still 32 because that is what the compiler said it is, not the system. It would be impossible to run 32-bit … | |
Re: you are trying to do it the hard way. fgets() and strtok() functions that make it very simple. fgets() reads a whole line, and strtok() splits it into its individual parts based on a token, such as a space, that you give it. [code] #include <stdio.h> #include <string.h> #include <stdlib.h> … | |
Re: [QUOTE=Narue]> there's a run-time assertion if the allocation size exceeds a certain limit, and 4294967295 is beyond that limit. [/QUOTE] The parameter to malloc is a size_t (on my compiler it is defined as unsigned long). So how in the world can you ever pass that function a value greater … | |
Re: A NULL pointer is a pointer that points to address 0 [code] const void *p = 0; [/code] | |
Re: I think the longest string that can be made in C or C++ is the maximum value of an integer (as defined by size_t). Compilers will concantinate string liters just by NOT using ';' between lines. Note the use of quotes below The semicolon ; only appears at the end … | |
Re: passing an object by value calls the copy constructor because a new copy is created -- and that would mean an infinite recursion. Also, it always faster to pass c++ class objects by reference than by value. | |
Re: stdio.h contains function prototypes (declarations) and structure definitions from the standard C stream library. You cann't write either a C or C++ that uses any of those functions without including stdio.h. If the program doesn't use anything from it, then there is no need to include it. | |
Re: c and c++ compilers do not do range checking on enumerations or pointers. It lets you hang yourself with a very very long rope if you want to. Its up to the programmer to validate data ranges and buffer sizes before using or doing something with them. Those are two … | |
Re: get it from the keyboard as a string instead of an integer, then create a loop to check each digit in the string. You don't need modules, division, shifts, or any other math operations, unless, of course, that is a requirement of the problem. | |
Re: you shouldn't call the constructor directly like in function show(). Do that in a set function. This works ok in VC++ 6.0 compiler. Nearly all c++ programs use set functions similar to below -- none use private constructors to do it. [code] #include<iostream> using namespace std; class A { private: … | |
Re: Your first example is ALMOST how to multiply two arrays. A[100] does not exist in an array with 100 elements. you have to create a loop and multiply each array element in array A by the corresponding element in array B. Then the result has to be stored someplace, either … | |
Re: do you want the drive letter of the drive on which the os is installed? such as "c:"? or the path that the program is starting from? argv[0] or win3w2 api function GetModuleFileName() will give you the latter. | |
Re: you didn't do anything "wrong". There are a lot of porting issues you must deal with when porting C programs to C++. Most (if not all) the errors you are getting are probably because the functions have not been prototyped before used in main(). You need the *.h file that … | |
Re: [QUOTE=sunnypalsingh]Both The Codes Works Fine.....Now What??Why Memory Allocation[/QUOTE] There are many many cases where you do not know the text that the character array contains. For example, suppose I ask you for your name. The program has to put the answer some place, if the pointer doesn't point to some … | |
Re: [code] o << num1.read_list(i);[/code] function read_list() returns void, so the above line will not compile. | |
Re: Are P, Q, A and B individual data elements? If they are then the first a. (P*Q) + (Q*P) + (R*S*T) + (R*S*T) + (T*R*S) I don't know the significance of the ' character, so the above may not be completly correct. | |
Re: How difficult the program is to port all depends on the program. If the program uses strickly ANSI C or C++ functions there should be few if any porting problems. But most programs use some hardware-specific functions. You will just have to take them one at a time. First attempt … | |
Re: yes. [code] char * foo() { static char array[] = "Hello World"; return array; } int* foo1() { static int array[20]; return array; } [/code] | |
Re: get a free compiler from [url]www.bloodshed.net[/url]. See sticky for books | |
Re: in VC++ 6.0 IDE create a "win32 Dynamic-Link Library" project. Step 1 of the wizard has 3 radiao buttons select "a DLL project that exports some symbols" then press Finish button. The wizard will generate the DLL project. Look at the *.cpp and *.h files. They will show you how … | |
Re: something like this will hold an unlimited number of strings that are of unlimited length. [code] const char *array[] = { "jane", "John Deer Company", "The quick brown fox jumped over the lazy dog", "Adam", "Smith" }; [/code] | |
Re: see the <limits.h>, which defines the max value of all integer types. Allocations cannot exceed those values. | |
Re: you probably created the wrong kind of project. You should have created a Console Application, not a Windows Application. With a Console Application your program compiled with no errors or warnings. Of course I had to add a main() function to the code you posted. | |
Re: put the dll in a place where the os can find it, one of the directories in the PATH or in the same directory as the program you are trying to run. | |
Re: not quite certain what you want. Do you want to convert the unsigned short to CString? CString's Format function is identical to sprintf() and printf(). [code] CString str; unsigned short test = 0x1234; str.Format("%X", test); [/code] Of course if you display the result, the string will be "1234". | |
Is there a c++ std:: function that will trim trailing spaces from std::string? I know how to do it myself, but I was wondering if anyone knows of something in <altorithms> or elsewhere? Thanks | |
Re: [URL=http://www.codeproject.com/cpp/ymatrix.asp]CodeProject[/URL] has at least one that you might find useful. | |
Re: seems to work with c++ STL classes too ;) [code] #pragma warning(disable: 4786) #include <iostream> #include <vector> #include <string> using namespace std; int main() { vector<string> array; array.resize(2); char* p1 = (char *)&array[0]; char* p2 = (char *)&array[1]; cout << p2-p1 << endl; cout << sizeof(array[0]) << endl; return 0; … | |
Re: This works with Dev-C++ but not with VC++ 6.0 (I think it is a compiler bug) [code] HWND hWnd = GetConsoleWindow(); ShowWindow(hWnd,SW_SHOWMAXIMIZED); [/code] ![]() | |
Re: most of the problems are typing errors -- such as using colon when semicolon is expected, and misspelled words. Using Dev-C++ I had to change the top like this: Note <iostream> without .h extension. [code] #include <iostream> // allows program to perform input and output using namespace std; // program … | |
_tempnam() always returns a filename in the "c:\\temp" directory, regardless of the parameters. This example was extracted from MSDN. I need to generate a unique filename in a directory other than c:\temp -- any ideas how to do that other than writing my own function? maybe a c++ solution? Note … | |
Re: elements of an array are not called "records". A record is something you play on a phonograph machine, history of your activities in prison, or a complete collection of data in a file. | |
Re: I would have written the first one like this [code] printf("|Val=%s",outString); [/code] but if your goal is to concantinate two strings into a single buffer [code] char buf[255]; strcpy(buf,"|Val="; strcat(buf,outString); //or (same as above) sprintf(buf,"|Val=%s",outString); [/code] Neither of the above two are safe because neither strcat() nor sprintf() check for … | |
Re: ever hear of [URL=http://www.google.com/search?hl=en&q=how+to+send+email+with+c%2B%2B&btnG=Google+Search]google[/URL] | |
Re: Your program is not what the question asked. It wants you to enter a 3-digit number all at one time, not one digit at a time. So your program should get the number as a string, then test each character of the string. Use fgets() to get they keyboard input. … | |
Re: what do you mean "it failes"? it won't compile? it won't run? what error(s) do you get? Note: unless its just a posting error, it needs a semicolor at the end of the cout line. Also, how is buffer declared? | |
Re: you cannot access class objects/methods from class static methods. There are at least two ways to overcome this: 1. pass a pointer or reference of an instance of the object to the static method, then access the objects through this pointer/reference. 2. make the object(s) static. | |
Re: only write out the number of bytes read. At some point (at end-of-file) the number of bytes read will be less than the buffer size. This would go much faster if you read/write with larger buffer size -- say 255 characters. [code] int main() { [color=red] char buf[255];[/color] ifstream fp_in("my.txt", … |
The End.