|
藍森林 http://www.lslnet.com 2006年6月6日 10:18
在linux下得出0長度子串(sstream)
[code]#include <string>;
#include <iostream>;
#include <fstream>;
#include <sstream>;
using namespace std;
string getmonth(string s)
{
//cout << s;
string month[12] ={"January","February","March",
"April","May","June","July",
"August","September","October",
"November","December"};
//cout << sizeof(month);
for(int i=0;i<12;i++)
{
if(month[i] == s)
{
stringstream stream;
stream << i+1;
string rs = "";
stream >;>; rs;
return rs;
}
}
return "00";
}
main()
{
string mm = "July";
cout << getmonth(mm);
//cout << s.find("j",0);
} [/code]
應是
stringstream stream;
stream << i+1;
string rs = "";
stream >;>; rs;
return rs;
這裡出問題了
但在win是無問題
有辦法解決嗎? |
在linux下得出0長度子串(sstream)
不要返回string,直接把你要接收string的變量用&傳入試一試 |
在linux下得出0長度子串(sstream)
[code] //Get the month (int convert to string)
string getmonth(string s)
{
//cout << "getmonth=" << s << "\n";
string month[12] ={"January","February","March",
"April","May","June","July",
"August","September","October",
"November","December"};
//cout << sizeof(month);
for(int i=0;i<12;i++)
{
if(month[i] == s)
{
stringstream stream;
stream << (i+1);
string rs = stream.str();
return rs;
}
}
return "00";
}[/code]
這樣行了,暈~~~ |
| |