6,741 Posted Topics
Re: Use strstr to find the string you want to remove and then copy over it. Someting along these lines: [code] char *p = strstr ( place, arg ); int start = p - place; int end = start + strlen ( arg ); memmove ( place + start, place + … | |
Re: The easiest way would be to maintain a sorted list as items are entered, then have the list take on queue behavior after all items have been entered. Is this a suitable solution? | |
Re: There's no hope for that code. Start over, this time paying close attention to a good C++ reference. | |
Re: >I want to ensure that the user puts in a name with characters and not use numbers. Why? Numbers would be a valid string, and forcing your players to enter alphabetic characters may be an unnecessary restriction. Especially since it requires more work and code from you, and therefore more … | |
Re: i is an integer, "," is a string. You can't compare them directly. Did you mean: [code] while ( first[i] != ',' ) [/code] | |
Re: You need to write an operator<< for BankAccount: [code] class BankAccount { public: //void setAccount(int num, double amount); taken out replaced by constructor BankAccount(int num, double amount); BankAccount(); int getBalance(); int getAccountNumber(); void deposit(double AnAmount); void withdraw(double AnAmount); [COLOR=Blue]friend ostream& operator<< ( ostream& out, const BankAccount& b ) { return … | |
Re: >what would you do different I wouldn't waste my time performing the calculations manually: [code] #include <ctime> #include <iomanip> #include <iostream> using namespace std; class Time { public: Time ( int hours = 0, int minutes = 0 ) { time_t t = time ( 0 ); data = *localtime … | |
Re: You have [b]got[/b] to be kidding! The error says that calArea needs to return a value. The definition of calArea is: [code] double Shape::calArea() { } [/code] How is that confusing? All you need to do is return a value: [code] double Shape::calArea() { return 0; } [/code] | |
Re: >1. how can i pause my cout output? or is it possible to do it without calling a system command Ask for input and discard it: [code] cout<<"Press enter to continue."; cin.ignore ( numeric_limits<streamsize>::max(), '\n' ); cin.get(); [/code] The call to cin.ignore() makes sure that there's no unwanted data in … | |
Re: Unless you're the kind of person that enjoys partitioning and installing operating systems, or you REALLY have to have a Linux partition, get a live CD such as Knoppix or Mandrake Move. It's so much easier. | |
Re: >(1) what exactly is programming, Programming consists of designing software, writing instructions in a programming language that execute steps which implement that design, testing the instructions to ensure that they work properly, and fixing any errors that occur. >(2) what exactly programmers do Programmers create software. :) >(3) Is it … | |
Re: >whole program is correct but at end it is not displaying correct result. Then the whole program is not correct. :rolleyes: >#include<stdio.h> This isn't needed. >main() This is illegal C++. Implicit int is not allowed, so you need to say: [code] int main() [/code] >for(int i=0;i<10;i++) This is not portable … | |
Re: >1. Why do you need Self-Referential Classes? It's the easiest way to implement non-contiguous data structures. You don't [b]need[/b] them, but they make life easier. >2. ^^^What is a Node, is it just a random name for this Class? [url=http://en.wikipedia.org/wiki/Node_%28computer_science%29]Node[/url] >3. what does the (const Node *) mean in It's … | |
Re: Which system are you compiling on, and which system are you compiling for? The error basically says that the virtual DOS machine is encountering errors with your 16-bit program on a 32-bit system. It could be something you're doing, or something you're not doing that you should be. Though I … | |
Re: [code] (int)Math.pow ( 2, b ); // Cast the result of pow to int [/code] | |
Re: >void main() Wrong, main returns int. >gets(vehicle.V_RegNo); Wrong, gets can never be made safe. Use fgets on stdin instead. >fflush(stdin); Wrong, fflush is only defined for output streams. stdin is an input stream. The equivalent correct code is: [code] int ch; while ( ( ch = getchar() ) != EOF … | |
Re: >void loadsave (); It's best to avoid using one function for two wildly different operations. >string convert; I'll assume that string.h defines a string class on your old ass compiler. Otherwise this is a ghastly error. >if (savedplayers >=1) I'd bet my next paycheck that you want to enclose the … | |
Re: Make this change and call it good: [code] double AirborneLocation :: distance() [COLOR=Blue]const[/COLOR] { [/code] | |
Re: Accelerated C++ by Andrew Koenig and Barbara Moo | |
Re: >Any ideas what could be causing this? With the amount of information you've given, it could be anything at all. | |
Re: >i would like to use a window for user interface instead of dos console. My first question is "why"? Introducing graphics should be done only after the students have a strong foundation in the core language and standard libraries. Otherwise, they'll find themselves battling C++ as well as whatever graphics … | |
Re: [code] user_name = 'user' for i in range ( 1, 100 ): user = user_name + str ( i ) print user else: print 'The loop is done' [/code] | |
Re: Try something more like this: [code] #include <cstdlib> #include <fstream> #include <iostream> #include <string> #include <vector> using namespace std; int main() { cout<<"An empty string or EOF will stop the program"<<endl; for ( ; ; ) { string name; cout<<"Enter a name to search for: "; if ( !getline ( … | |
Re: Most likely you're trying to use a standard template class without including the header. Post the code. | |
Re: [url=http://java.sun.com/j2se/1.5.0/docs/api/]Math.pow(2, b)[/url] | |
Re: The easiest way to get a truly global variable (accessible across multiple translation units) is to declare it in the common header, and define it in a special translation unit: [code] /* header.h */ #include "defs.h" extern int memory[SIZE]; [/code] [code] /* header.c */ #include "header.h" int memory[SIZE]; [/code] Now … | |
Re: >is ArrayList better than Vec It depends on your needs. If you need a synchronized list and it has to be compatible with Java 1.1 then Vector is an option. Otherwise, ArrayList should be preferred, and Collections.synchronizedList will give you synchronization (which ArrayList does not have by default). >how do … | |
Re: Huh? Did something change? ;) Minor gripe: Your fontage seems a little small, and if it's small for me, a lot of people may have a problem with it. | |
Re: >Alternatively you can use the functions itoa and atoi respectively. itoa isn't a standard function, so it may not be available. | |
Re: >I have tried #include <cstring> That header has nothing to do with MFC. It's a header with functions and types for working with C-style strings (ie. arrays of char terminated with '\0'). Might I suggest the std::string class? It's easier to work with than CString, and also provides conversions to … | |
Re: [code] string string1 ("DDRA"); string string2 ("DDRB"); string string3 ("0021"); string string4 ("CLR"); string string5 ("LDAA"); string string6 ("LDAB"); string string7 ("READ"); string string8 ("ABA"); string string9 ("STAA"); string string10 ("END"); [/code] This is a sign you should be using an array. [code] int counter; counter=0; if (string1.find(filename.c_str())) ++counter; if … | |
Re: I notice a lack of attempt on your part. It seems like you're asking [b]us[/b] to do [B]your[/B] work for you. It doesn't work that way around here. Sorry. | |
Re: >what is the problem What are the symptoms? I can point out a lot of stuff that could be considered a "problem", but since we can't read your mind, we don't know which of them you're referring to. Dave also asked you a question and suggested a way to improve … | |
Re: What part of it are you having trouble with? And don't say all of it, because I'll stop helping if you act like you want us to give you solutions without any effort on your part. | |
Re: [code]if (!getline(cin, search)) { count; }[/code] If getline fails, you basically do nothing here. You're reading the value of count (0) and doing nothing with it. [code] { ifstream in("MarkScheme.txt"); if (!in){ cerr<<"Mark Scheme not found"<<endl; return EXIT_FAILURE; } } // End local [/code] This also does practically nothing. Because … | |
Re: An array is not a modifiable lvalue, so you can't assign to one using the = operator. You need to copy each element from the source array to the destination array individually. This is best done with a loop, but since your array only has two elements, you can do … | |
Re: Throw the whole thing in a loop and break from the loop if the user enters something that isn't valid: [code] #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXLINE 256 int main(void) { char str[MAXLINE], rev[MAXLINE]; int i, length; for ( ; ; ) { /*-------------------------------------------- * Read string and … | |
Re: >ages[b-1]=ages[i]; That's your error. i isn't an index, it's a content value, and the value could very well exceed 999, which is the largest possible index for ages. Change that line to: [code] ages[b-1]=ages[b]; [/code] You probably also want to restructure your code so that it has specific sections for … | |
Re: [code] #include <algorithm> #include <iostream> #include <iterator> using namespace std; int main() { int a[] = {5,7,4,6,3,8,0,1,9,2}; sort ( a, a + 10 ); copy ( a, a + 10, ostream_iterator<int> ( cout, " " ) ); } [/code] ;) | |
Re: I wouldn't recomment assembly as your first language. There's a different dialect for every architecture you program on, and even though the language is relatively small and simple, the problem is putting small and simple pieces together. It's easier to work with a language that doesn't require you to build … | |
| |
Re: The list of things you've done wrong is too long for me to go into detail, so here are the biggies: 1) gets is wrong 2) main should not be called recursively 3) feof is not meant to be a loop condition 4) Your constructs are very inconsistent At least … | |
Re: The way you've worded this is confusing. Is the data model like this? [code] Stock No: Price Description Customer No: Name Address Order No: Customer No Date Order Line: Order No Stock No Quantity [/code] If not, be more specific. >The software uses a datagrid attached to the orderline table … | |
![]() | Re: If the file is in the current working directory, it's just a matter of tacking on the extension and opening the file: [code] string name = "derrick"; ifstream in ( ( name + ".txt." ).c_str() ); [/code] If the file is not in the current working directory, you must supply … ![]() |
Re: Those tutorials aren't horrid, but one should be wary of misinformation and poor practice when reading them. | |
Re: Okay, you've explained what you're trying to do and the code shows how you're going about it. However, you've neglected to tell us what you're code doesn't do that you want it to. I don't know about everyone else, but I don't have time to analyze every program that somebody … | |
Since Dani refuses to post, and you people should care enough about the community to follow the log closely, I attached it. ;) | |
Re: You can search for a number easily: [code] int array[BIG_SIZE]; int n = 0; // ... int r = rand(); int i; for ( i = 0; i < n; i++ ) { if ( r == array[i] ) break; } if ( i == n ) array[n++] = r; … | |
Re: It depends on how you're reading the records. The easiest way is to treat each record as a line and use getline to read them. getline will extract the newline character for you. If you're reading character by character then you may need to use the ignore member function of … |
The End.