1,608 Posted Topics

Member Avatar for n.aggel

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()) {}

Member Avatar for n.aggel
0
191
Member Avatar for musicmancanora4

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 …

Member Avatar for Lerner
0
138
Member Avatar for boujibabe

>>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 …

Member Avatar for Lazaro Claiborn
0
275
Member Avatar for sakura_fujin

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.

Member Avatar for Lerner
0
221
Member Avatar for SHWOO

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 …

Member Avatar for WaltP
0
176
Member Avatar for rQQt2

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.

Member Avatar for rQQt2
0
449
Member Avatar for endsamsara

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, …

Member Avatar for endsamsara
0
123
Member Avatar for alejo

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 ( …

Member Avatar for alejo
0
119
Member Avatar for torbecire

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 …

Member Avatar for Lerner
0
97
Member Avatar for bananenflip

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 …

Member Avatar for bananenflip
0
302
Member Avatar for bananenflip

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?

Member Avatar for WaltP
0
89
Member Avatar for arfmal

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 …

Member Avatar for Lerner
0
163
Member Avatar for boujibabe

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.

Member Avatar for WaltP
0
133
Member Avatar for Matt Tacular

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; …

Member Avatar for Matt Tacular
0
89
Member Avatar for raydogg57

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 …

Member Avatar for WaltP
0
554
Member Avatar for loslos

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] …

Member Avatar for loslos
1
115
Member Avatar for pointers

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.

Member Avatar for WaltP
0
200
Member Avatar for k3n

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 …

Member Avatar for Lerner
0
198
Member Avatar for iaaan

>>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 …

Member Avatar for iaaan
0
146
Member Avatar for bluecat

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.

Member Avatar for Lerner
0
84
Member Avatar for flageolet

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 …

Member Avatar for flageolet
0
220
Member Avatar for edek

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 …

Member Avatar for Ravalon
0
951
Member Avatar for cusado

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 …

Member Avatar for Lerner
0
126
Member Avatar for itchap

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.

Member Avatar for Infarction
0
99
Member Avatar for dmmckelv

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 …

Member Avatar for ~s.o.s~
0
103
Member Avatar for elodie

>>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 …

Member Avatar for Lerner
0
1K
Member Avatar for sivaslieko++

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 …

Member Avatar for sivaslieko++
0
126
Member Avatar for murschech

>>Think of cin>> as that bloke who works great by himself but messes things up in a team. I like that analagy. Well done!

Member Avatar for Ravalon
1
160
Member Avatar for Gunner54

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 …

Member Avatar for WaltP
0
167
Member Avatar for sTorM

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]

Member Avatar for Lerner
0
131
Member Avatar for syruspayne

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 …

Member Avatar for 80s
0
323
Member Avatar for kenshihimura

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 …

Member Avatar for Lerner
0
153
Member Avatar for jobra

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.

Member Avatar for John A
0
233
Member Avatar for Kompot

>>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 …

Member Avatar for Lerner
0
96
Member Avatar for Sandtimes

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. …

Member Avatar for Sandtimes
0
641
Member Avatar for backstabber

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?

Member Avatar for backstabber
0
129
Member Avatar for Ryan Steyn

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 …

Member Avatar for jbennet
0
109
Member Avatar for joelw

>>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 …

Member Avatar for Ancient Dragon
-1
322
Member Avatar for newbie2c++

>>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 …

Member Avatar for Lerner
0
84
Member Avatar for joelw

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 …

Member Avatar for Lerner
0
389
Member Avatar for solomon grundy

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 …

Member Avatar for Infarction
0
128
Member Avatar for Cnaly

>>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. …

Member Avatar for Bench
0
116
Member Avatar for jessiegirl

>>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 …

Member Avatar for WaltP
0
160
Member Avatar for queenma7

>>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 …

Member Avatar for John A
0
2K
Member Avatar for sparkid

[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); …

Member Avatar for sparkid
0
86
Member Avatar for JoBe

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 …

Member Avatar for WaltP
0
349
Member Avatar for limergal

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] …

Member Avatar for limergal
0
112
Member Avatar for dmmckelv

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 …

Member Avatar for Lerner
0
97
Member Avatar for bencwai

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 …

Member Avatar for Lerner
0
83
Member Avatar for pugg09

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 …

Member Avatar for Lerner
0
112

The End.