ifstream input_data;
input_data.open("input.dat");
int n;
double x;
input_data >> n >> x;
string s;
input_data >> s; /* read a word */
getline(input_data, s); /* read a line */
char ch;
input_data.get(ch);
char ch;
input_data.get(ch);
if ('0' <= ch && ch <= '9') /* it was a digit */
{ input_data.unget(); /* oops - didn't want to read it */
int n;
input_data >> n; /* read integer starting with ch */
}
input_data.close();
ofstream output_data;
output_data.open("output.dat");
output_data << n << " " << x << "\n";
output_data.put(ch);
output_data.close();
datafile.open("employee.dat", ios::in | ios::out).
or a string variable that contains a file name.input_data.open("input.dat");
string input_name =
cwin.get_string("Please enter the file name:");
ifstream input_data;
input_data.open(input_name);
input_data.open(input_name.c_str());
input_data.open("c:\\homework\\input.dat");
double read_data(istream& in);
max = read_data(infile);
max = read_data(cin);
string input = "January 23, 1955";
istringstream instr(input);
string month;
int day;
string comma.
int year;
instr >> month >> day >> comma >> year;
int string_to_int(string s)
{ istringstream instr(s);
int n;
instr >> n;
return n;
}
ostringstream outstr;
outstr << setprecision(5) << sqrt(2);
string output = outstr.str();
string month = "January";
int day = 23;
int year = 1955;
ostringstream outstr;
outstr << month << " " << day << "," << year;
string output = outstr.str();
string int_to_string(int n)
{ ostringstream outstr;
outstr << n;
return outstr.str();
}
21:30
9:30 pm
9 am