1,358 Posted Topics
Re: Unless it's more feasible for you to use a friend function (mostly for reusability), I think you would be better off incorporating your read/write directly into your class. This way, you can tell an object to write itself to the file or tell it to read its own data from … | |
Re: [QUOTE=pseudorandom21;1483629]In your example: tolower is in <cctype> and is a C function.[/QUOTE] I'm sure Narue knows that. The more important questions are: [list][*]Why do you think there is a problem? [*]Do you know why she wrote the call to it the way she did?[/list] @OP: glad you figured it out | |
Re: [QUOTE][CODE]... int main () { int Score; //ret is for return :) another personal preference ... return Score; } [/CODE][/QUOTE] Unless you have a VERY GOOD reason, this is not a good "personal preference". Your main() [B]must return zero (0)[/B]. Any other return value besides zero (0) indicates some sort … | |
Re: [QUOTE][CODE]#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { char bend = '#';//#@ beginning and end char cues = '?'; int n,x,y ; cout <<"Please enter number of ?'s :"; cin >> n; cout<< bend<< endl; for(y=1;y<=n;y++) { for(x=1;x<=y;x++) { cout<< cues <<bend; } cout<< endl; … | |
Re: Since you're asking about MFC, I'm not sure I can help, but I think you should clarify something. Are you trying to create a CGI script? If not, what are you trying to create? | |
Re: [QUOTE][CODE]int main(); // function main begins program execution { int main=0; int digit_one; //store digit one int digit_two; //store digit two int digit_three; //store digit three int digit_four; //store digit four[/CODE][/QUOTE]Lose the semi-colon after main() on Line 1. Having it there changes it from a function header to a function … | |
Re: [QUOTE=mcriscolo;1480050]Check out line 23 - what's that equal sign ("=") all about? Remove that and see what happens.[/QUOTE] There is substantially more going on here than just that. The problem is, the OP didn't give us the header, so we don't know how the class is declared. The errors are … | |
Re: [B]>>Does that sound about right? I just want to make sure I have the understanding locked down.[/B] It looks like you have the right idea. If you make an operator function a member of a class/struct (or a friend of the class/struct) it will have access to the data members … | |
Re: Huh??? Why would you want to do that? Care to clarify your reasoning? If we have a reason, it may be easier to give you a more valuable response and/or suggest a better alternative. | |
Re: [QUOTE][CODE]46. for(i>0;i<size;i++)[/CODE][/QUOTE] The first statement in a for loop's header must be an assignment statement, not a relational statement. | |
Re: Use escaped double-quote characters (\"):[CODE] << "<input class = \"btn\" name = \"calculate\" type = \"button\" VALUE=\"Shortest Path\" onClick=\"sendDataST(document.getElementById('begP').value + '\n' + document.getElementById('endP').value + '\n')\">\n" [/CODE] I've changed most of them. I think that the ones I didn't change will be okay, but it's been a while since I've written … | |
Re: The point Narue is trying to make is that you have to actually try to do something with a function/feature/component before you can begin to understand it. It's called practice. You'll never learn anything if you don't step into the unknown once in a while. There is no magic crystal … | |
Re: [QUOTE=Sundayy;1474869]Here is my second attempt, I am now getting on line 27, an error; no match for 'operator >>' in std::cout >> "What is (X3*360):\012"'. Can you please tell me how to fix it, see my code below. Thank You CODE [CODE] //Variables: //X1 = Total Number of Seconds //X2 … | |
Re: I believe the post directly in front of yours answers your question... Did you even read the thread before you hijacked it? [QUOTE=Banfa;1191658]From winreg.h [code] #define HKEY_CLASSES_ROOT (( HKEY ) (ULONG_PTR)((LONG)0x80000000) ) #define HKEY_CURRENT_USER (( HKEY ) (ULONG_PTR)((LONG)0x80000001) ) #define HKEY_LOCAL_MACHINE (( HKEY ) (ULONG_PTR)((LONG)0x80000002) ) #define HKEY_USERS (( HKEY … | |
Re: "setprecision" is a stream manipulator. Most of the stream manipulators are found in [URL="http://www.cplusplus.com/reference/iostream/manipulators/"]the <iomanip> header[/URL] (which you haven't #included). | |
Re: As Narue explained, a struct and a class are essentially the same. The only real difference is that members of a struct default to the [B]public[/B] access level while members of a class default to the [B]private[/B] access level, unless otherwise specified in the declaration of the struct/class. In some … | |
Re: What do you mean by "summarize"? Can you provide a sample of intended output? The new version of Line 11 is an accumulator, is this your intent? Are you trying to create a column of values then display the accumulated total? If so, you'll have to move Line 11 down … | |
Re: Chdek your spilling Nad your cAPS. (In case you can't understand that, it says "Check your spelling and your CAPS".) Does this:[CODE] inFile >> stocknam >> numshar >> buypric >> currpric; stockdata.setstockName(stocknam); stockdata.setnumShares(numchar); stockdata.setbuyPrice(buypric); stockdata.setcurrPrice(currpric);[/CODE] Match These:[CODE] string stockName; double numShares; double buyPrice; double currPrice;[/CODE]??? Answer: NO. Not only are … | |
Re: I noticed this:[QUOTE][CODE]else if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') vowels++;[/CODE][/QUOTE] What happens if the read character is "capital" ('A', 'E', 'I', 'O', or 'U')? This will miss those because there is a difference. I think it would be advisable for you to either create an isvowel() function or "normalize" the input by using tolower(). Either … | |
![]() | Re: I believe the order of operations is messing you up. Try this instead, for all 3 getlines: [CODE]getline(inventdata,(items[i]).unitPrice);[/CODE] |
Re: On Line 85 of this code, what is your reason for decrementing your iterator called "it"? If I trace your program's execution, this is the line that triggers the error. EDIT: nvm.... looked at something wrong... have to look again... <[I]section erased[/I]> EDIT 2: Due to how the scope of … | |
Re: Well, for starters, you need to actually create a loop. You don't have any loop structure in this code. Just remember, everything that you want to execute multiple times needs to be within the statement block controlled by the loop.[CODE] void someFunction() { //any code here will only run once … | |
Re: I'm not too sure how much I should say. This post reeks of a homework assignment to me. I have a feeling that this would be difficult to compile because the declaration is upside-down. Your function implementations are attempting to use member variables before they are declared, which could lead … | |
Re: Depending on how you get the values into your array, you could possibly use dynamic allocation, but there will be an efficiency hit because of the extra allocation and copying operations. | |
Re: [B]>>ios_base::binary does not actuall change how the data is written to the file[/B] That's not entirely true. While a binary file can still still be a human-readable text file, the binary file mode changes the way [B]certain characters[/B] are handled while written to and/or read from a file. It causes … | |
Re: [B]>>Every time the compiler prints an error message during compilation, that message includes the number of the line with the problem.[/B] And, in many IDEs, you can double-click the error message to be taken to the location of the error. | |
Re: I find the "I am god, do as I say" phrasing rather repugnant... | |
Re: >>Wouldn't it give me an error or something then? Not at compile time. It is likely to at run-time though. You were just fortunate that it didn't. All that the compiler really cares about is that the variable representing the array is a valid pointer to the proper type of … | |
Re: [B][I]>>(Ravenous)You should use ctime instead of time.h[/I][/B] [B]>(Nandomo)Same thing it's just a matter of choice, switched it anyway.[/B] Actually, Ravenous is correct, and there is a difference. The <ctime> header is the modern (post-Standard) version of <time.h> and should always be used for modern code. It defines and uses the … | |
Re: [B]>> I can't see it, can you? [/B] I'm afraid you're not the only one. It's completely unreadable. [URL="http://www.gidnetwork.com/b-38.html"]You need to work on your formatting.[/URL] [URL="http://www.daniweb.com/forums/announcement8-3.html"]And Learn how to use code tags.[/URL] | |
Re: The function addBigInt() is a [B]member function[/B]. As such, it only has one (1) argument, as you have written. That argument receives the [B]right-hand[/B] value from the statement. [B]The other argument is [I]the implied "this" pointer[/I] and need not be explicitly declared as part of the function[/B]. | |
Re: [URL="http://www.daniweb.com/forums/announcement8-2.html"]Have you written any code yet? If so, what do you have?[/URL] It would be a good idea for you to share the relevant sections of it. From an educational standpoint, it is better [B]for you[/B] if you let us see it and discuss it with you and/or critique it. … | |
Re: You have 3 different instances where the copy constructor is used and 1 instance where you've used the compiler-provided assignment operator. To simplify the code a little and make it easier to read, Let's expand your main() (which by the way, regardless of program size, should have an int return … | |
Re: A "string literal" is a constant pointer to char. You can't assign a constant pointer to a non-constant pointer. That's a conversion that allows you to edit a constant using a "backdoor". You will need to use functions from [URL="http://www.cplusplus.com/reference/clibrary/cstring/"]the <cstring> header[/URL], such as strncpy(), to perform the assignment so … | |
Re: Since I don't know exactly what your situation is, I'm just going to throw this out there as a possibility. You could also use an enumeration:[CODE] #include <iostream> using namespace std; enum myEnum {BASE_VAL = 0, FIRST_VALUE, SECOND_VALUE, VALUE_TEN = 10}; int main() { myEnum example(FIRST_VALUE); //select any valid member … | |
Re: If used, the arguments to main() are always going to be at least [ICODE]argc = 1 [/ICODE]and [ICODE]argv[0] = "[I]executableName[/I]"[/ICODE]. As you add more command line arguments, argc will increase and argv will get more elements. I find that it tends to help if you draw parallels between main() and … | |
Re: Yes. I think you need to take another look at the wording in your book, paying particularly close attention to where the "only" is placed in the sentence and what it's attached to grammatically. Speaking in reference to static functions, it probably says something like:[list][*]"a static function does not have … | |
Re: I can think of 2 possible issues here: [list=1][*]Unguarded headers causing multi-include errors [*]Circular definition errors that can't be resolved because of how your code is currently written. [/list] You'll have to describe the problem better and post the relevant code. | |
Re: Your post is somewhat incomplete, making it difficult to make sense of. In and of itself, this snippet is a very bad piece of code: [list=1][*]You're trying to base a comparison on an uninitialized variable (variable 'x'). [*]You're trying to increment it when you don't even know if the value … | |
Re: What exactly is Car::get_gas() intended to do? It looks like you have it set up to do 2 different jobs, but you don't correctly implement/complete either job... Is it intended to add gas to the vehicle ([iCODE]void Car::get_gas(double)[/iCODE]), or is it intended to calculate fuel consumption ([iCODE]double Car::get_gas(void)[/iCODE])? Notice the … | |
Re: [QUOTE=jackmaverick1;1458936]I have tried these tips and they havn't worked. You don't think it's an issue with the compiler... Here's the code [CODE] class player { public: int money; int roll; int spotID; private: char name[45]; bool banker; void getOriginalValues() { } }; player p1,p2,p3,p4,p5,p6; [/CODE] I get errors for all … | |
Re: What's "the 4018 warning"? I'm afraid there aren't many of us that know what each error/warning number means. Read the input as a string. Then, step through the string like an array of char. While stepping through the string, determine what kind of character it is and respond accordingly. For … | |
Re: [QUOTE]But the output window just says: 1>------ Build started: Project: Ans7, Configuration: Debug Win32 ------ ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========[/QUOTE] A compiler wouldn't "just say" that, especially not the MS Visual Studio compiler. There must be some errors that it's reporting, please share them. … | |
Re: [QUOTE][CODE]point::point(int x, int y) { this -> x = x; this -> y = y;}[/CODE]This is wrong. All data members are initialized before entering the constructor. For built-in types there's no guarantee it's initialized at all before entering the constructor. So what you wrote yield to undefined behaviour.[/QUOTE] Other than … | |
Re: As I understand it, the .NET libraries are Object-Oriented libraries that use a Microsoft extension to C++ called "C++/CLI" (among other things, I don't know which version is the "official" version). Technically, a statement such as "Console::WriteLine("Hello World!");" is valid C++ syntax, but it's using parts of the .NET library … | |
Re: There is no "perfect" definition for a class/template. What a class/template should do and/or contain is completely situational. Or do you mean something else that requires a more complete/perfect description from you? | |
Re: [QUOTE][CODE]void(*fnctn)(void(*)(int *,void **),int(*)(void**,int*));[/CODE][/QUOTE]Boy, that is pretty messy, always remember, CODE blocks and whitespace are your friends. (Although I don't think any amount of whitespace will help this...) I think you may be correct, ravenous. I don't mess with them much either, but it sure looks like it's a prototype declaring … | |
Re: [QUOTE=guest3;1456957]is it possible to create array of pointers and set + get its elements using a class like this?. make changes/add to the class as needed. show actual code, if possible. [CODE]class t { t::t() { } t::~t() { free(array); array = NULL; } void set_size(int s) { array = … | |
Re: [QUOTE="UnseenTerror"][CODE]//... 73 case 3 : 74 entrees++ ; 75 printf("Entrees:\n") ; 76 break ; //...[/CODE][/QUOTE] There's no call to entrees() here... You need to actually call the function, then store the return value. [URL="http://www.cplusplus.com/doc/tutorial/functions/"]Some info on functions.[/URL] | |
Re: [QUOTE=jfunchio;1455359]I need help getting my function to overload the + operator to add a integer and a Rational object. Right now I am able to add two rational objects with my overloaded +. I made a second overloaded + function and now I am able to add an integer and … |
The End.