我试图在一个字符串中设置一个随机数,但是idk我怎么能让程序知道我想要随机数而不是字母n。
我正在使用visual studio 2008,Windows Forms C ++
System::Drawing::Font ^Fuente = gcnew System::Drawing::Font("Arial Black",50);
System::Random ^r = gcnew System::Random(System::DateTime::Now.Ticks);
char n=r->Next(1,100);
buffer->Graphics->DrawString("n",Fuente,System::Drawing::Brushes::WhiteSmoke,50,50);,50);
答案 0 :(得分:3)
System::Drawing::Font ^Fuente = gcnew System::Drawing::Font("Arial Black",50);
System::Random ^r = gcnew System::Random(System::DateTime::Now.Ticks);
int n=r->Next(1,100);
buffer->Graphics->DrawString(n.ToString(), Fuente, System::Drawing::Brushes::WhiteSmoke,50,50);,50);
可能是你的目标
答案 1 :(得分:0)
在绘制字符串时使用引号 - 这是一个字符串文字。
您应该使用stdlib.h itoa函数将您的数字转换为字符串。
char number[3];
int n = r->Next(1,100);
itoa(n, number, 10); //number to convert, string to save value in, base
buffer->Graphics->DrawString(number,Fuente,System::Drawing::Brushes::WhiteSmoke,50,50);,50);