Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange problem with ostringstream 1

Status
Not open for further replies.

xwb

Programmer
Jul 11, 2002
6,828
0
36
GB
I'm not sure what is happening with this
Code:
std::ostringstream oss;
oss << "??/??/??";
std::string date = oss.str();
std::cout << date.c_str();
I get \??
If I try
Code:
oss << "??/";
I get a warning about a newline
 
Happens with iostream as well
Code:
#include <iostream>
int main ()
{
   std::cout << "??/??/??" << std::endl;
   return 0;
}
Looks like the / is some sort of regular expression search character. To get the result I want, I have to change it to
Code:
#include <iostream>
int main ()
{
   std::cout << "??\/??\/??" << std::endl;
   return 0;
}
 
Actually that gives warnings, changed to
Code:
#include <iostream>
int main ()
{
   std::cout << "?\?/?\?/??" << std::endl;
   return 0;
}
 
Yet another thing I didn't know about C after using it for 25 years!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top