比如有一个计算器程序,用户先选择加减乘除。比如结果是 strOper = "+";//选择了加法然后再输入二个数字 intNum1= 2 和 intNum2 = 3怎么样将 intNum1 strOper intNum2连接起来,变成 2 + 3,并能计算出结果。谢谢

解决方案 »

  1.   

    CString str;
    str.Formart("%d %s %d = %d",intNum1, strOper, intNum2,intNum1+intNum2);
      

  2.   

    Format  多了个r ,呵呵``
      

  3.   

    我这里提示:
    error C2661: “System::String::Format” : 没有重载函数接受 5 个参数
    怎么回事啊?以下是我的源代码:是一个.net控制台程序#include "stdafx.h"#using <mscorlib.dll>using namespace System;int _tmain()
    {

    String *strSel,
       *strOper;

    int intSel,
    intNum1,
    intNum2,
    intSum;


    Console::WriteLine(S"请选择计算方式(输入1~4):");
    Console::WriteLine(S"1,加法\n2,减法\n3,乘法\n4,除法\n");
    strSel = Console::ReadLine();
    intSel = Int32::Parse(strSel);
        

    if (intSel == 1)
    strOper = "+";
    else if (intSel == 2)
    strOper = "-";
    else if (intSel == 3)
    strOper = "*";
    else if (intSel == 4)
    strOper = "/";


        Console::WriteLine(S"请输入第1个数字:");
    intNum1 = Int32::Parse(Console::ReadLine());
    Console::WriteLine(S"请输入第2个数字:");
    intNum2 = Int32::Parse(Console::ReadLine());

    intSum = intNum1 + intNum2;
    Console::WriteLine(S"您选择的是{0}法,最终结果是{1}.",strOper,intSum.ToString());

    }
      

  4.   

    应该在 intSum = intNum1 + intNum2; 这一行改动.谢谢!
      

  5.   

    控制台程序~???没有CString 类的
    用char 好了,``int a=1;
    int b=2;
    char str[100];
    memset(str,0,100);
    sprintf(str,"%d + %d=%d",a,b,a+b);
    要加#include <stdio.h>
    #include <string.h>头的`