以下代码是较大翻译程序的一部分。下面的代码要求用户输入一行,而不仅仅是将其写回。有没有一种方法可以让我不用每次都写一行,而是在标准输入中传递整个文件等“translate.txt”,程序可以将其逐行写回,并在行尾时产生错误到达了 ?
#include <iostream>
#include <string.h>
#include<stdio.h>
#include<fstream>
using namespace std;
using namespace std;
void PL() {
char line[BUFSIZ];
while( cin.good() ) {
cout<<"Type line now"<<endl;
cout<<"\n";
cin.getline(line, sizeof(line));
cout<<"\n"<<endl;
string mystring = string(line);
// supposed to Parsing string into words and translate//
//but just reading back input for now//
cout<<"You typed:"<<mystring<<endl;
cout<<"\n"<<endl;
}
}
int main() {
PL();
}
您是否期望有一种方法将文件传递给您的程序?
executable < file
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)