oh, wait, its changed now
oh, wait, its changed now
so, should key be a string or a char? should i have it declared as "char key" or "string key"?
A string and an array of chars have similiar functionality. Strings are preferred unless it's part of the program specification (some teachers have a fetish for char arrays (c-strings))
Could you restate the problem?
ok thank you, i have it as "string key[26];" is that correct?... ugh.. now my letters don't show on the output screen like they are supposed to.. *sigh* is it a lost cause? I hope not.
annnndddd.... i also have an infinite loop after entering the characters and the input file
Strings resize themselves automatically, so you don't need to declare how much memory they need or resize them yourself. However, since you know that you want to store 26 letters, you can use the reserve() function to set aside space for precisely 26 chars.
this is my code nowCode:#include <string> using namespace std; #include <fstream> #include <iostream.h> #include <stdlib.h> int main() { ........ int i; ........ string infilename; ........ ifstream fin; ........ string key[26]; ........ for (i = 0;i < 26;i++) { ............ cout << "Please enter your replacement for character" << key[i] << ": \n"; ............ cin >> key[i]; ........ } ............ cout << "Please input a file (input)" << endl; ............ cin >> infilename; ........ if (fin.fail()){ ................ cout << "Error - file opening failed" << endl; ................ } ........ while (!fin.eof()) { ............ if (fin.eof()) ............ break; ............ for (int i = 0; i < 26; i++) { ............ cout << "Your new message is: \n" << key[i] << endl; ............ } ........ } ........ fin.close(); ........ system("PAUSE"); ........ return 0; }
Last edited by Andy717; 04-07-2005 at 01:00 PM.
This isn't looking good....make sure you understand the code people tell you to use before you use it. Period.
I was helping another student out, but he had gotten so many chunks of code from other people that he had no idea how his program worked anymore and when he asked me for help the only thing I could tell him was to start over.
Basically, not to get you depressed or anything, but if you don't understand it now, don't expect to understand it just by having people spoon feed it to you. You're going to need to put in the time and effort to learn the language on your own.
-edit-
And another thing, there's a lovely button called the edit button Use it so you don't have to keep making new posts.
it wont let me post the whole code... ok, fixed
1) Where are you copying it from?
2) How are you pasting it?
3) What is the board saying about your code?
well, my prof said he'll meet me (thank goodness) in about an hour and 10 mins... so, i hope he'll help me... well, he'll only help me with really specific things, but, at least it's help... and yeah, im trying to learn it, but... it's hard when i can't talk with anyone about it, or whatever... ehh.. oh well..
Last edited by Andy717; 04-07-2005 at 01:15 PM.
well, thanks everyone for your help... im out..