Reputation: 41
Here is my function that has the following code in it. Note: It's already declared in the main and runs perfectly fine.
void displaySeatingChart(char seats[][colvalue], float prices[rowvalue])
{
string filename = "seatingChart.dat";
ifstream inFile(filename);
for (rows = 1; rows <= rowvalue; rows++)
{
string newLine;
cout << "Row #" << rows << "\t";
for (cols = 1; cols <= colvalue; cols++)
{
inFile >> newLine;
cout << newLine;
}
cout << endl;
}
}
rows
is 15 and cols
is 30. My problem is that the cout << newline
prints literally the entire file (which is basically all #). How can I print just 15 characters and not like 1500?
Upvotes: 0
Views: 783
Reputation: 206717
inFile >> newLine;
This reads everything until a whitespace character. If your file contains all the characters in one line and contains no white spaces, it makes sense that the above line reads the contents of the entire file.
To read one character at a time, use
char c = inFile.get();
Your inner loop would be:
for (cols = 1; cols <= colvalue; cols++)
{
char c = inFile.get();
cout << c;
}
See the documentation for istream::get()
for additional info.
Upvotes: 3