简体   繁体   中英

no spaces while printing the output after reading the file

I'm trying to print the contents of the file to output but the output is missing the spaces from the file. I've also tried using infile >> noskipws >> ch; but it displays only the first word from the file.

int process_infile(int shift)
{   
    char c[1000];
    ifstream ifile;
    ifile.open("D:\\example.txt") ;
    if(!ifile)
    {
        //cout<<"Error in opening file..!!";
        error();
        //getch();
        exit(1);
    }
    cout<<"Data in file = ";
    while(ifile.eof()==0)
    {
        ifile >> c;
        cout << c;
        //encodeCaesarCipher(c,shift);
    }       
    ifile.close();
    getch();
    return 1;
}

try

while(ifile.eof()==0)
{
  string line;
  getline(ifile,line);
  cout << line;
        //encodeCaesarCipher(c,shift);
}   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM