I want to have a space as an element of a string in c ++
this is my code:
#include <iostream>
#include <string.h>
using namespace std;
int main(){
int n;
cin>>n;
cin.ignore();
int cont=1;
while(n--){
cout<<"Message #"<<cont<<endl;;
string mensaje[2000];
for (int i = 0; i < 2000; ++i){
mensaje[i]="0";
}
for (int i = 0; i < 2000; i++){
cin>>mensaje[i];
if(mensaje[i]!="0"){
cout<<"["<<mensaje[i]<<"]";
}
}
cont++;
cout<<endl;
}
return 0;
}
and when I do the test with a text file to put from the terminal in Linux let's say ./example < example.txt
This is the text file:
2
... --- ...
.--- --- -... -.. --- -. . ..--.. ..-. .. -. . -.-.--
print this to me:
Message #1
[...][---][...][.---][---][-...][-..][---][-.][.][..--..][..-.][..][-.][.][-.-.--]
Message #2
and I need it:
Message #1
[...][ ][---][ ][...]
Message #2
[.---][ ][---][ ][-...][ ][ ][-..][ ][---][ ][-.][ ][.][ ][ ][..--..][ ][..-.][ ][..][ ][-.][ ][.][ ][-.-.--]
Thanks for your cooperation.
Sorry for not having specified it before, I am solving the 11223 grape exercise and therefore I require the 2000 strings, and I need to know when there are spaces or not because I need to make a kind of Morse code translator, and the space is to identify if it is another letter and if they are two spaces in a row they are a space in the morse already translated.