简体   繁体   English

读取文件后打印输出时没有空格

[英]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; 我也尝试过使用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);
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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