just want to know how I can get a string from stdin which contains whitespaces? I tried fgets and scanf("%[^\n]",str) but it's still not working in C.
I tried the program to remove whitespaces from a given string in c++. Here's is my code but it's not working.
#include <iostream>
#include <string>
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while (t--) {
char s[1000];
cin.getline(s, 1000);
// cout<<s;
int i;
for (i = 0; s[i]; i++) {
if (s[i] != ' ')
s[i] = '\b';
}
for (i = 0; s[i]; i++)
cout << s[i];
// cout<<endl;
}
return 0;
}