1,608 Posted Topics
Re: You could try changing this: public: CFoutTest(string filename="test.dat"); to this: public: CFoutTest(); CFoutTest(string); in the declarations and then in the definitions use this: CFoutTest() : fout("test.dat") {} CFoutTest(string filename) : fout(filename.c_str()) {} | |
Re: If the goal is to display the hexadecimal equivalent of a char on the screen using C++ I/O and you don't want to do all the conversions yourself, then options to atoi() and sprintf() with "%x" format include converting the char to int with strol() and using the ios::hex flag … | |
Re: >>why are we defining elements By that I assume you mean why intialize elements to some default value. Assuming that is correct, the answer is: when you declare an array none of the elements are initialized, just like when you declare a single element. Therefore, if you try to access … | |
![]() | Re: This is C++ so the only place you need the keyword struct in this program is on line 10. I don't know that it's wrong, illegal, or creates ambiguity to use it the other places you have, but it's certainly more typing. |
Re: What joeprogrammer means is that this if (found = true) is an assignment statements whereas this if(found == true) is a comparison statement. Assignment statements always return true, so the if statement is always true, irrespective of the value of found before this statement. Also, because you're assigning true to … | |
Re: Where is the variable sz defined and given avalue, and what value does it have in relation to dimensions of the the variable called data? Also, please indent code so it is easier to read. | |
Re: Not on topic: 1) it should be int main(), not void main(). 2) don't use the return result of eof() as the conditional for a loop to run or not. Sooner or later it will get you into trouble. On topic: 1) You want to read from file to cadena2, … | |
Re: put the do in before this line: cout << " Please enter two numbers: "; and the while after the closing brace of the switch statement. [code] } //end of switch statement cout << "\n Would you like to perform another calculation? " << endl; cin >> option; }while ( … | |
Re: The cpp file used to define the methods in the h file shouldn't have main() in it. The driver program, which is also a cpp file, will have main in it. It would have been nice if the driver files were given a different extension than the files used to … | |
Re: I suspect that English isn't your first language, and I know C++ isn't. Unfortunately, that increases the chance that you will phrase your questions in an imprecise manner. Such is the case with your current post. Please try to restate your question in a more precise manner. For example, we … | |
Re: I still don't understand what you want to do. Do you want to write a comparable version of the posted code in C++? Do you want to insert some C++ code into the code you currently posted? What exactly do you want to do? | |
Re: If each line of the file contains exactly 4 pieces of information separated by whitespace (spaces or newlines or tabs, etc), then there is no reason you can't use >> to read each piece of information from the file. [code] while (fin >> n) { vector1.push_back(n); for(i = 0; i … | |
Re: I found this when looking up informtaion about time_t: In the GNU system, you can simply subtract time_t values. But on other systems, the time_t data type might use some other encoding where subtraction doesn't work directly. I'd suggest using difftime() to calculate the elapsed time interval. | |
Re: You could try something like this: [code] bool validInput = true; cout << "Enter a binary number to convert: " << endl; cin >> binaryToConv; int len = binaryToConv.length(); for(int counter = 0; counter < len; ++counter) { if((binaryToConv[counter] != 0) && (binaryToConv[counter] != 1)) { validInput == false; break; … | |
Re: an array of strings is a 2D array of type char. If the array is to hold up to 10 strings and each may be up to 256 char each, then you could declare it like this: char arrayOfStrings[10][257]; You can use a loop with 2 conditionals to control the … | |
Re: Off topic, but in the spirit of trying not to learn bad habits, and trying to avoid bugs that can be difficult to find when trying to determine why you don't get the results you expect on trial runs with known input as you test your code, the following [code] … | |
Re: If you have a table displaying the relative precedence of the various operators and you are familiar with the concept of precedence, then it's pretty much a look up every time you want to do something until you have it memorized. | |
Re: First, when you post code to this board please enclose it in code tags. You can get instructions how to use them by reading the water marks in the text entry box for the board or by reading the sticky posts at the top of the board. Then, from the … | |
Re: >>The furthest i have gotten so far is to be able to add the .txt files line by line. Sometimes it's easier to read the file field by field rather than line by line. In this case the file consists of a series of records, with each record having 3 … | |
Re: Sometimes casts will work, sometimes you need to change types, etc. Without knowing what type you have and what type you want to change into it's not possible to say what the best approach might be. | |
Re: When including iostream I expected to see cout and cin rather than printf() and scanf() which I always thought were defined in cstdio (or stdio.h if you have an old compiler). I also don't see where you declare the variable antwoord and I doubt it's stuck somewhere in iostream. You … | |
Re: As you probably know, in C++ it is possible to overload the ^ operator to do whatever you want it to, though predefined it is the exclusive OR bitwise operator. I've never seen it used in the context of your post. In what context and with which language did you … | |
Re: In C++ you could use : as the terminating char to getline() to do the job in a whiff. To my knowledge fgets() is the closest you can get to getline() in C, though, and it doesn't have a terminating variable as an argument. I would either read the file … | |
Re: The project is going to depend on what tools you have available. For example, if you are comfortable with STL and trees you could try to implement a B or a B+ tree class using the guidelines for an STL container. | |
![]() | Re: Tracking down runtime errors can be a hassle. There is no right way to do it. If you can get somebody else to do it for you, good luck. Learing how to do it yourself, however, is probably better in the long run. I would either learn how to use … |
Re: >>I still don't get this line: std::string input = OpenFileDialog->FileName.c_str(); Methinks OpenFileDialog->FileName may be of type AnsiString, not of type STL C++ string. I believe AnsiString is a string class used that mimics the STL C++ string class, but it isn't the same as the STL C++ string class; and … | |
Re: Like Ravalon I've never done this before either. My thought would be if you aren't comfortable developing sparse arrays you might be able to mimic the sparse array protocol proposed using a full binary tree of the same height as the original tree instead. To do this I'd first determine … | |
Re: >>Think of cin>> as that bloke who works great by himself but messes things up in a team. I like that analagy. Well done! | |
Re: First off the question is about C++ strings and the code is using C style I/O and C style strings. To read in a string containing whitespace (for example, a sentence containing more than 1 word) using C I'd suggest fgets(), though if you want to endure some heckling from … | |
Re: I'd consider developing another class to represent a Player and Game. Maybe something conceptually along these lines: [code] Player Card hand[5]; int numCards; int handValue; int runningTotal; valueHand(); Game vector<Player> players; int numHandsPlayed; housePays(); determineWinner(); [/code] | |
Re: To get to the pseudocode level try writing out how to generate a fibonacci series from 1 to 50 and how to determine if a number above zero and under 51 is prime. Then try to shape the narative description into variables and things you do to or with variables … | |
Re: As I understand it, Visual Basic is a language, C is a language, and C++ is a language, but VC++ is an Integrated Development Environment proprietary to Microsoft. However, VBC++ doesn't fit any of those criteria. If you are using the C++ language then you would read a file using … | |
Re: Why not subtract the difference in hours between GMT and New York from the hour in GMT, adjusting for MN when necessary? I believe hour is one of the members of the tm struct. | |
Re: >>I cabt mark place where i already was Without seeing or knowing more about your code it's not easy to say for sure what to do. However, assuming you have each position in the grid represented as on object of type cell, or whatever, then you could have each cell … | |
Re: The body of the main() function should be enclosed in curly brackets just like any other function body. In C++ user defined type is declared with keywords class or struct, not structure. The struct/class type needs to be declared before any variable of that struct/class type is declared or used. … | |
![]() | Re: Just out of curiosity what are the restrictions set on solving the puzzle. That is, could you use a tree or stacks or someother structure besides arrays or are you restricted to use of just arrays? ![]() |
Re: Compilers turn the code you write into instructions your computer will understand. A linker links files to your program and finds the functions and variables contained within those files. An IDE (Integrated Development Environment) usually contains both a compiler and a linker and also usually has other software bundled in … | |
Re: >>The problem is that a cin for a numeric will leave the ENTER key in the keyboard buffer and that is OK with cin and other numbers but not with strings, thus we must remove it on our own. This is correct. However, the code you posted has several errors … | |
Re: >>I want to create 1)spaces between the questions Not sure what you mean by this. If you want the questions to be like double spaced lines that you type for english class papers then just call endl twice in a row like this: cout << endl << endl; If you … | |
Re: To determine the average of all elements except the lowest you need to write a routine that obtains the sum of all values except the lowest and divide the sum by the number of elements in the array minus one. Thus this: average = sum / j; should probably be … | |
Re: And there's some animal screaming bloody murder out my window at the moment too, but without anymore information about the problem I'm just as helpless in either case. Please indicate what the problem is, not just that you have one. Also, please enclose your code in code tags---read the FAQ … | |
Re: >>it only reads the lines Thats what getline() does. It places all information in the input stream up to the indicated terminating character into the string indicated. If it the end of file indicator, EOF, before it finds a terminating char it will also cease input into the string indicated. … | |
Re: >>How do I loop in a loop to find the minimum and maximum nubers Let the first element be the largest (or smallest) element in the array. If the array only has one element then that must be true. If the array has more than one element it may or … | |
Re: >>QUESTION: i dont know if am initializing the variables correctly. The ability to answer this question on your own is part of the process called debugging. It's a skill you're going to need to prosper in this endeavor so you might as well learn how to do it early. The … | |
Re: [code] void enterScores(int *, const int); void calculateAverage(int *, const int, double &); void calculateStandardDeviation(int *, const int, double &, double &); int main() { const int SIZE = 6; int score[SIZE]; double averageScore = 0.0; double stdDev = 0.0 cout << fixed << setprecision(2); enterGrades(score, SIZE); calculateAverage(score, SIZE, averageScore); … | |
Re: Hope something in here meets your needs and helps you understand the syntax. char * wordArr[10]; means wordArr is an array of 10 char pointers, not that wordArray is a pointer to 10 char arrays. char * word = new char[10]; means word is a pointer to a char array … | |
Re: string [50] makes no more sense than int[50]. Given you have included the string header file you supposedly will be using STL strings, which is fine. Under that scenario you could declare a single string like this: string s; or an array of strings like this: string s[50]; but string[50] … | |
![]() | Re: First , thank you for using code tags. Second, aye carumba! What a mess! Please try editing your post removing the color tags. If you didn't add the color tags manually and/or if you aren't allowed to do edit your post to remove the color tags, then paste your code … |
Re: I've never heard of hash_map so I enetered that term in Google's search box and the result indicates several references from reputable sources. I suggest you do the same and follow up as needed. In summary it appears as though map and hash_map are not the same but hash_map is … | |
Re: In C look up fgets(). In C++ using C style strings look up getline(), which is an istream method, and because ifstreams and fstreams are also istreams you can also use it with an open ifstream. [code] ifstream if("myFileName.myFileExtension"); if(!fin) { cout <<"Unable to open file by the name of … |
The End.