Hey guys, i am working with a program to basically read an input for a file and then storing it into a vector. my text file is called Sample.txt and contains data like this..
How are you coping with programming?
The quick brown fox jumps over me.
Here are my codes..
int main (){
vector<string>myVec; // declaring a vector
int threshold ;
cout << "Enter threshold number: " ;
cin >> threshold; //store user input into interger variable
int i = 0;
fstream readFile("sample2.txt"); // prepare to read from file
string Numeral ;
char delimeter = ' ';
string word ;
while (getline(readFile,Numeral, delimeter))
{
word = Numeral;
i ++;
myVec.push_back(word);
}
int g = myVec.size();
for(int i = 0; i < g ; i ++){
cout << myVec[i] << endl;
}
cout << i << endl;
cout << g << endl;
}
Well, the output i am trying to achieve is basically listing down each word in the text file like this..
Expected Output
How
are
you
coping
with
programming?
The
quick
brown
fox
jumps
over
me.
But for some reason, my output keeps coming out like this.
Current Output
How
are
you
coping
with
programming?
The
quick
brown
fox
jumps
over
me.
There is a gap before "The". I guess it is being caused due to "The" being in a new line. Is there any way i am able modify my codes to read each word in my text without worrying bout newlines and all?