C++字符串类型转换问题

C++字符串类型转换问题

各位大佬们,初学者自己做了一个腾讯的一个笔试题:
把一个字符串的大写字母放到字符串的后面,各个字符的相对位置不变,且不能申请额外的空间。

下面是我自己写的代码,但是代码有问题,在代码里标注了,说是从string到char类型的转换问题,但是百度了也试了几个解决方案还是不行,请大佬们不吝解答,谢谢。

#include
#include
#include

using namespace std;

int main(){
	string Test[20];
	string test1;
	string test2;
	int len;
	int count = 0;
	std::cout << "String?: ";
	std::cin >> Test[20];
	len = sizeof(Test);
	for (int i = 0; i < len; i++) {
		char c = Test[i];//!!!这里出问题
		if ( c >= 'a' && c <= 'z' ) { 
			count += 1; 
			test1[i] = c;
		}
		else { 
			if (c >= 'A' && c <= 'Z') { 
				test2[i] = c; 
			} 
		}

	}
	std::cout << test1 << test2 << std::endl;
	return 0;
}

你可能感兴趣的:(代码)