Data type while inputting the string

Here, the data type of ch is defined as char and we give a long input when running the code.

As char reads single characters, how will this code read the long input (say ‘aabbcccd’) as the user inputs just once?

hey @sonalbera can you share the screenshot of code or the code itself from where you are taking reference too, so that i can clear your doubt,

I’m talking about the code for Queue-08- First non-repeating character implementation.

in the video at line 12, 13, bhaiya initializes as :-:

char ch;
cin>>ch;

After building the code, he inserts a string like ‘aabcb…’ .
So my doubt was that as char can read a single character, how does it read this string by itself as the user inputs the string altogether just once??

Video link;- https://online.codingblocks.com/app/player/150556/content/153674/6647/lecture

Hey @sonalbera i have seen the video. You will see that we have taken input in ch , and yes you are right it will contain only one character element not the entire string. So what are we doing is taking single character element one at a time until character element equals to ‘.’ that is mentioned in while condition. So we are not taking whole string in char a , but we are taking one element at a time in char a. Hope this will clear your doubt :slight_smile:

One last thing…char can store a single character. So when the user enters the long string, how does it store that till ‘.’ is found?

You are not storing string in just one go, you are storing it using only a single single character

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.