c_cpp 从给定的字符串中删除空格 - GeekforGeeks

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 从给定的字符串中删除空格 - GeekforGeeks相关的知识,希望对你有一定的参考价值。

/*
http://ideone.com/fl1XGN
http://www.geeksforgeeks.org/remove-spaces-from-a-given-string/
http://www.practice.geeksforgeeks.org/problem-page.php?pid=454
*/

#include <iostream>
#include <string>
#include <vector>
using namespace std; 

int main() {
	int t;
	cin >> t;
	cin.ignore();
	while(t--){
		string s, result="";
		getline(cin, s);
		int len = s.size();
		for(int i=0; i<len; i++){
			if(s[i] != ' ')
				result += s[i];
		}
		
		cout << result << endl;
	}
	
	return 0;
}

以上是关于c_cpp 从给定的字符串中删除空格 - GeekforGeeks的主要内容,如果未能解决你的问题,请参考以下文章