Before, I start constructing a code for my main assignment. I would like to get an advice on my following code. Is there anything I can improve on this code and also, if there is a mistake can someone point it out. Im just asking the user to type in the input and the output file and from that oint onwards, it will open both of those two files. Also is my main scope of the area ok?
As a C++ programmer, it's advised that you use std::strings instead of char arrays.
I don't see a closing brace anywhere for your main function (which should also return something by the way).
Then of course there's the use of usingnamespace std; in global scope, but whatever that advice is almost cliche and you can do whatever you want.
Yeah, the only REAL recommendation is using std::strings. You can cut down the number of parameters for your openfile_makefile() function by using strings, and it makes the input less of a hassle.
Understood you for the first part :) when your talking about cutting down the parameters, I'm a little unsure about that... What exactly should I pull out and why?and I'm not sure how adding strings would cut down my parameter list :(
you dont need the sizes because strings have sizes "built" in to them. i wouldnt use using namespace std; its very bad practice and can lead to a number of clashes.
And now I'm a little lost.i saw a code in my book illustrating steing [14] how would this code work? I can't recall it and I think there is no such thing as a string array :( I Couod be wrong though
no c-string wouldnt be better. why do you think so? and writing steing[14] creates an array of 14 cells for type whatever_type_steing_is. and of course you can have an array of strings. you can have an array of anything except keywords.
The reason I think c string would be better is because I won't be able to allow the user to enter up to certain amount. For instance, I onky want a student name up to 15 characters. Once it has reached to 15, it will not read the other characters if there more then 16.
In steing, from my knowledge as a beginner, string will read the entire sentence, though yes I can just use cin operator to get the first part of the sentence before white space is found and ignore the rest of character or use getline until a certain delimiter is found.
Sorry if I'm bugging you too much :D I have never seen an example of a steing array. How does it look like. For instance, the character array would be something like
1 2 3
char name[16]
For (int row=o;row<16; row++)
Cin>>name[row]
in this particular code, the user will keep writing in a character.
For string array. How would it detect when I'm on the second index of string. I know I didn't explain this really good, but the character array would know what the second index is of the cstring....once again, definately lacked in explaining this, but any example of a steing area would help :(
I read in the book that if im declaring it as a string variable, then when I open the file, I need to convert that into a c-string. So would this be correct?
The reason I think c string would be better is because I won't be able to allow the user to enter up to certain amount. For instance, I onky want a student name up to 15 characters. Once it has reached to 15, it will not read the other characters if there more then 16.
Ignoring extraneous input is not a very good solution, whether you choose to use C style strings or C++ strings.
I will keep that in mind cire. Meanwhile, for this code i understood every part of this code except lines 11-13. Promt is a reference parameter, but you have it as cout..prompt. Furthermore, what is line 12 all about, especially ws. I have never seen that in my programming class. Is it some variable?
Promt is a reference parameter, but you have it as cout..prompt.
I don't understand what you're asking here.
Furthermore, what is line 12 all about, especially ws. [...] Is it some variable?
Line 12 is all about what the comment says it is about. It extracts any leading whitespace from the input stream (std::cin, here.) This makes it impossible for the user to give us an empty string on line 13, so we don't have to check for that condition on line 15.