I have a program that is supposed to read in integers and output asterisks.
I have the program working fine except that if zero is inputted that line is removed.
I want the program to still input the zero value by skipping a line in the text, but it just eliminates the line all together. Will someone please help me understand this?
here is the portion of code that writes the asterisks to a file as they are inputted and then outputs the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
cin>>number;
if(number==0){myfile<<" \n";}
while(number>0){number--;myfile<<"*";}
myfile<<endl;
times--;line++;}
myfile.close();
//read the file and print it
ifstream inputfile("asterisks.txt");
char buffer[128];
while (inputfile >> buffer)
{
cout<<buffer<<endl;
}
inputfile.close();
//read the file and print it
ifstream inputfile("asterisks.txt");
char buffer[128];
while (inputfile.getline(buffer,128) )
{
cout<<buffer<<endl;
}
inputfile.close();
The >> operator is skipping over the empty lines in the file.