samedi 21 février 2015

cout not working in c++ after taking line input (getline)

I am in midway of implementing fairplay algorithm, but I noticed that cout statements are not working


Below is my code. Note that all required header files are included and there are no compilation errors (by far my knowledge). The program runs without errors and I get terminated command (again, with no errors).


But there is no output at the same time. Even the cout test 2 is not reflected in output.


NOTE: I get output if I use endl at the end of each cout statement, but thats inconvenient here as I want to print the matrix. Besides there must be a easy way rather than writing enld every time



int main()
{

int i,j,k,x,y,z;
bool status[24]={false};
char map[5][5]={0};
string key;
cout<<"Enter the key"<<endl;

cout<<"Test 1";
getline(cin,key);
cout<<"Test 2";
x=key.length();

for(i=0;i<x;i++)
key[i]=toupper(key[i]);

for(i=0;i<x;i++)
{
y=key[i]-65;
if(status[y]==0)
status[y]=1;
}

cout<<"Adding the main key string";

i=j=k=z=0;
while(k<x)
{
if(j==5)
{
i++;
j=0;
}
map[i][j++]=key[k++];
}
cout<<"Adding the remaining alphabets";
while(k++<25)
{
if(j==5)
{
i++;
j=0;
}
while(status[z++]==false)
map[i][j++]=z+64;
}

cout<<"Output matrix";
for(i=0;i<5;i++)
for(j=0;j<5;j++)
{
cout<<map[i][j];
}


return 0;


}


Aucun commentaire:

Enregistrer un commentaire