Reading in characters and creating array c++ -
How to go about reading in a row of characters from a file. The first program reads in an integer from the file. This number indicates how many letters to be read in the next step. Reads the next letter and stores them in an array. So how do I create the 'char' variable, so that I can read Michael's characters correctly to display in the array.
file.txt: 8 Michael im inputfile & gt; & Gt; Integer, from there, I need an integer to make four mikes [integer] of this array; Then, in the head, in the head
To answer your question:
#include & lt; Fstream & gt; using namespace std; Int main () {ifstream f ("file.txt"); Int n; F & gt; & Gt; N; Char chs = new four [N]; For (Int i = 0; I & lt; n; ++ i) F & gt; & Gt; Chs [i]; // chs delete [] Do something about chs; } But, I go along (if your Michael appears on your line): #include & Lt; Fstream & gt; #include & lt; String & gt; using namespace std; Int main () {ifstream f ("file.txt"); Int n; F & gt; & Gt; N; String str; Gateline (f, arr); }
Comments
Post a Comment