hey guys, i have a pretty easy question (i think).
my output is this:
1. 5 23 1979 2 16 1972 Second
whereas, 1 is the count, and there is also two dates, and then
it tells you which one is older.
my question is, how do i get a leading zero on the 5 and the 2?
when i do setw and setfill, it fills the entire line with zeros before and after.
it's really annoying. i was thinking about maybe seperating the digits somehow.
They are all declared as variables. (month1, day1, etc.)
thanks guys.
ps, here's the code.
int month1, day1, year1;
int month2, day2, year2;
int count;
ifstream fin;
ofstream fout;
fin.open("lab31.dat");
fout.open("lab31.out");
if(!fin)
{
cout<<"Can't open the input file.";
return 1;
}
fout<
my output is this:
1. 5 23 1979 2 16 1972 Second
whereas, 1 is the count, and there is also two dates, and then
it tells you which one is older.
my question is, how do i get a leading zero on the 5 and the 2?
when i do setw and setfill, it fills the entire line with zeros before and after.
it's really annoying. i was thinking about maybe seperating the digits somehow.
They are all declared as variables. (month1, day1, etc.)
thanks guys.
ps, here's the code.
int month1, day1, year1;
int month2, day2, year2;
int count;
ifstream fin;
ofstream fout;
fin.open("lab31.dat");
fout.open("lab31.out");
if(!fin)
{
cout<<"Can't open the input file.";
return 1;
}
fout<
[Error: Irreparable invalid markup ('<setw(43)<<setfill('-')<<"-"<<setfill('>') in entry. Owner must fix manually. Raw contents below.]
hey guys, i have a pretty easy question (i think).
my output is this:
1. 5 23 1979 2 16 1972 Second
whereas, 1 is the count, and there is also two dates, and then
it tells you which one is older.
my question is, how do i get a leading zero on the 5 and the 2?
when i do setw and setfill, it fills the entire line with zeros before and after.
it's really annoying. i was thinking about maybe seperating the digits somehow.
They are all declared as variables. (month1, day1, etc.)
thanks guys.
ps, here's the code.
<lj-cut text="...">
int month1, day1, year1;
int month2, day2, year2;
int count;
ifstream fin;
ofstream fout;
fin.open("lab31.dat");
fout.open("lab31.out");
if(!fin)
{
cout<<"Can't open the input file.";
return 1;
}
fout<<setw(43)<<setfill('-')<<"-"<<setfill(' ')<<endl;
fout<<setw(2)<<"#"<<setw(15)<<"First"<<setw(14)<<"Second"<<setw(12)<<"Older?"<<endl;
fout<<setw(43)<<setfill('-')<<"-"<<setfill(' ')<<endl;
count=0;
while(fin>>month1>>day1>>year1>>month2>>day2>>year2)
{
count++;
fout<<setw(2)<<count<<".";
fout<<setw(6)<<month1<<setw(3)<<day1<<setw(5)<<year1
<<setw(6)<<month2<<setw(3)<<day2<<setw(5)<<year2;
//**** problem is here ^^
if(year1<year2)
{
fout<<setw(11)<<"First"<<endl;
}
else if(year2<year1)
{
fout<<setw(12)<<"Second"<<endl;
}
else if(month1<month2)
{
fout<<setw(11)<<"First"<<endl;
}
else if(month2<month1)
{
fout<<setw(12)<<"Second"<<endl;
}
else if(day1<day2)
{
fout<<setw(11)<<"First"<<endl;
}
else if(day2<day1)
{
fout<<setw(12)<<"Second"<<endl;
}
else
{
fout<<setw(10)<<"Same"<<endl;
}
}
fout<<setw(43)<<setfill('-')<<"-"<<setfill(' ')<<endl;
return 0;
}
my output is this:
1. 5 23 1979 2 16 1972 Second
whereas, 1 is the count, and there is also two dates, and then
it tells you which one is older.
my question is, how do i get a leading zero on the 5 and the 2?
when i do setw and setfill, it fills the entire line with zeros before and after.
it's really annoying. i was thinking about maybe seperating the digits somehow.
They are all declared as variables. (month1, day1, etc.)
thanks guys.
ps, here's the code.
<lj-cut text="...">
int month1, day1, year1;
int month2, day2, year2;
int count;
ifstream fin;
ofstream fout;
fin.open("lab31.dat");
fout.open("lab31.out");
if(!fin)
{
cout<<"Can't open the input file.";
return 1;
}
fout<<setw(43)<<setfill('-')<<"-"<<setfill(' ')<<endl;
fout<<setw(2)<<"#"<<setw(15)<<"First"<<setw(14)<<"Second"<<setw(12)<<"Older?"<<endl;
fout<<setw(43)<<setfill('-')<<"-"<<setfill(' ')<<endl;
count=0;
while(fin>>month1>>day1>>year1>>month2>>day2>>year2)
{
count++;
fout<<setw(2)<<count<<".";
fout<<setw(6)<<month1<<setw(3)<<day1<<setw(5)<<year1
<<setw(6)<<month2<<setw(3)<<day2<<setw(5)<<year2;
//**** problem is here ^^
if(year1<year2)
{
fout<<setw(11)<<"First"<<endl;
}
else if(year2<year1)
{
fout<<setw(12)<<"Second"<<endl;
}
else if(month1<month2)
{
fout<<setw(11)<<"First"<<endl;
}
else if(month2<month1)
{
fout<<setw(12)<<"Second"<<endl;
}
else if(day1<day2)
{
fout<<setw(11)<<"First"<<endl;
}
else if(day2<day1)
{
fout<<setw(12)<<"Second"<<endl;
}
else
{
fout<<setw(10)<<"Same"<<endl;
}
}
fout<<setw(43)<<setfill('-')<<"-"<<setfill(' ')<<endl;
return 0;
}
