且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 V8 中将整数转换为字符串?

更新时间:2023-02-03 08:55:48

你没有说错误的本质,但我猜你的输出字符串的末尾被破坏了,因为你正在实例化一个字符串从一个整数.V8 将该数据解释为 const char * 数据.你应该从你的 int 实例化一个整数.您的最后一行将如下所示:

You don't say the nature of the error, but I'm guessing that the end of your output string is mangled, because you're instantiating a String from an int. V8 is interpreting that data as const char * data. You should instantiate an Integer from your int. Your last line will look like this instead:

return String::Concat(String::New("The sum is: ") , Integer::New(sum));