0

したがって、次のように 2 つの char 配列を連結する必要がある演習があります。

const int MAXI=100;
char group[MAXI+7]="things/"
char input[MAXI];

cin >> input;
//Doing something here!
cout << group << endl;

-- things/input_text -- を返すように何かを起こさなければなりません。

注意が必要なのは、ポインタ、文字列ライブラリ、またはあらゆる種類の動的配列の使用が許可されていないことです。

何をすべきか?

編集:印刷する必要はありません。変数に値が必要です:things / input_text、他の何かに使用するつもりです!

EDIT2: < string > ライブラリを使用できません。つまり、そのライブラリでは strcat() などを使用できません。次のようにトリガーされる別のモジュールが提供されています。

void thing(group, stuff, more_stuff);

それでおしまい。

4

2 に答える 2

3

このようなもの?

#include <iostream>

using namespace std;
const int MAXI=100;

int main()
{
    char group[MAXI+7]="things/";
    char input[MAXI];
    cin >> input;
    for(int i=0; i<MAXI; i++)
    {
        group[7+i]=input[i];
        if(input[i]=='\0') break;//if the string is shorter than MAXI
    }
    cout << group << endl;
}
于 2013-04-05T18:19:43.893 に答える