Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID


We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

stuck using .getline() and .get URGENT

So the assignment is to read in numbers from a .txt file and return a histogram. The symbol is to be found in the .txt file. I'm having trouble reading in the symbol.

The format of it is: S * Where I'm supposed to skip the "S" and the whitespace.

Here's the code I have so far

using namespace std;

int bin[20];

int main(){

char file[50], new_file[50];
char peek;
char junk[100],S;
char symbol;
ifstream input;
ofstream output;
int i,j, data;

cout << "Enter the file you wish to open: ";
cout << "What would you like to save the file as?: ";
cin >> new_file;;

cout<<"Open Failed"<<endl;
while((peek = input.peek())!=EOF){
if(peek == '#'){
input.getline(junk, 100);
\if(peek == 'S'){
\ input.getline(symbol);
\ do{
\ input.get(symbol);
\ }while(symbol == ' ');

input >> data;
cout << "Value = " << data << endl;
cout << endl << endl;
output << "Input File: " << file << endl << endl;
for(j=20; j>=0; j--){
cout << setw(3) << (j*5) << "|";
output << setw(3) << (j*5) << "|";
for(i=0; i<20; i++){
if(bin[i] > (j*5)){
cout << setw(3) << symbol;
output << setw(3) << symbol;
cout << " ";
output << " ";
cout << "|" << endl;
output << "|" << endl;
cout << " ---------------------------------------------------------------" << endl;
output << " ---------------------------------------------------------------" << endl;
cout << " ";
output << " ";
for(i=1; i<=20; i++){
cout << setw(2) << (i*5) << " ";
output << setw(2) << (i*5) << " ";
cout << endl << endl;
output << endl << endl;

return 0;

With the problem being in the area that I put in comment lines.

Apparently I'm supposed to use two different getline() functions to do this, but either through getlines or if statements, I just need it to work. My teacher hasn't explained how to use the getline function in class and it's due tomorrow before class...thanks
Sign In or Register to comment.