"Philip Goisman" <go*****@physics.arizona.edu> wrote in message
news:66**************************@posting.google.c om...
Hi,
Hope someone can help. I have the following c++ program which
compiles fine in gcc2.96, but won't compile in gcc3.2.2:
//FMain.cpp
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
int main()
{
int RunCurr = 66;
char* before = { "data/geom." };
char* after = { ".xml" };
std::ostringstream GeomFileName;
GeomFileName << before << setw(6)
<< setfill (48) << dec << RunCurr << after << ends
;
cout << GeomFileName.str() << endl;
return 0;
}
There are two problems:
1. The i/o manipulators are in namespace std.
2. GCC 3.2 is finding setfill(48) ambiguous. I tried your code on
several modern compilers, and only como 4.3.3 failed to complain of
this ambiguity. Off the top of my head, I'm not sure whose right.
Anyway, the following compiles on GCC 3.2:
int main()
{
int RunCurr = 66;
char* before = { "data/geom." };
char* after = { ".xml" };
std::ostringstream GeomFileName;
GeomFileName << before << std::setw(6)
<< std::setfill((char) 48)
<< std::dec << RunCurr << after << std::ends ;
std::cout << GeomFileName.str() << std::endl;
return 0;
}
You could also use something like this, which is easier to read.
const char zero = 48;
GeomFileName << before << std::setw(6)
<< std::setfill(zero)
<< std::dec << RunCurr << after << std::ends ;
HTH
Jonathan