c++ code works in gcc2.9 not in gcc3.2.2

P

Philip Goisman

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::eek:stringstream GeomFileName;

GeomFileName << before << setw(6)
<< setfill (48) << dec << RunCurr << after << ends ;

cout << GeomFileName.str() << endl;

return 0;
}

Any help is appreciated.

Regards,

Philip
 
K

Kevin Goodsell

Philip said:
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:

What errors did it give?
//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::eek:stringstream GeomFileName;

GeomFileName << before << setw(6)
<< setfill (48) << dec << RunCurr << after << ends ;

It's called std::ends, and you shouldn't be using it.
cout << GeomFileName.str() << endl;

std::cout and std::endl.
return 0;
}

Any help is appreciated.

Regards,

Philip

-Kevin
 
J

Jonathan Turkanis

Philip Goisman said:
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::eek:stringstream 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::eek:stringstream 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
 
R

red floyd

Jonathan said:
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::eek:stringstream 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 ;
even better would be:

GeomFileName << before << std::setw(6)
<< std::setfill('0')
<< std::dec << RunCurr << after << std::ends;

That way you don't have the implicit reliance on ASCII encoding of
character values.
 
J

Jonathan Turkanis

red floyd said:
even better would be:

GeomFileName << before << std::setw(6)
<< std::setfill('0')
<< std::dec << RunCurr << after << std::ends;

That way you don't have the implicit reliance on ASCII encoding of
character values.

Certainly, if that's what the OP wants. He went to the trouble of
specifying 48, though, so I'm assuming he had some good reason.

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top