char S[4], T[4];
cin >> S;
cin >> T;
分别输入"ABC"和"EFG"值后发现S会包含了T的内容.S="ABCEFG" T="EFG". 为什么会有这种情况?是不是buffer问题?
我用这个版本还是有问题,而且当S字符串被全部转成大写后,T字符串也跟着转成大写了.感觉怎么像变成共用地址了?
#include <iostream>
#include <string.h>
#include <iomanip> //for cout setw()
#include <stdio.h>
using namespace std;
//Sequence S and T
char S[4], T[4];
int alph_len = 0, sta_len = 0;
int sLength = 0, tLength = 0;
void main()
{
//Input alphabet number
cout << ("Input alphabet number:\n");
cin >> alph_len;
cout << ("Input state number:\n");
cin >> sta_len;
//Input S & T values
cout << "Input S:" ;
cin>>S;
cout << "Input T:";
cin>>T;
sLength = strlen(S);
tLength = strlen(T);
strupr(S);
strupr(T);
}