+ 1

Does s.size() mean the length of string s?

In Pig Latin, I try to make a loop with s.size(). However, when I check s.size(), it only returns the length of a word. Do you know how to fix this, and what do I need to use for knowing the length of a string? Thank you very much.

9th Feb 2022, 10:57 AM
adeadaccount
11 Answers
+ 1
Can you show your try..?
9th Feb 2022, 11:07 AM
Jayakrishna 🇼🇳
+ 1
Well, it is just a kind of a simple loop like this: for (int i = 0; i < s.size(); i++) { t=t+s[i]; } For example, the input is "Hello World", but it only takes the "Hello" part and ignore the "World" part.
9th Feb 2022, 11:15 AM
adeadaccount
+ 1
Manav Roy Can you tell me more details about the getline function?
10th Feb 2022, 5:05 AM
adeadaccount
+ 1
Both the size() and length() methods return the length of a string - This is in terms of bytes. A char is one byte in memory. So as long as you are using characters which are stored in one byte, you’ll be fine. For the spaces, you can use the getline method: std::string str; std::getline(std::cin, str); This will store the user input in str and keep the spaces.
10th Feb 2022, 8:03 AM
DinoBambino
0
How are you reading input? pls Post full code ? May be you are using cin>>s; Huy082125
9th Feb 2022, 11:45 AM
Jayakrishna 🇼🇳
0
Huy082125 Is there a built-in function for that? It would make a lot of lives easier
9th Feb 2022, 2:49 PM
Da GD Bot
Da GD Bot - avatar
0
Huy082125 it's better to show your full code if you not solved it yet.. That may help to find mistake. As already posted by above one's, To read a line of string, use string str; getline(cin, str);
10th Feb 2022, 1:08 PM
Jayakrishna 🇼🇳
0
Manav Roy thank you, I really really needed this
11th Feb 2022, 3:34 PM
Da GD Bot
Da GD Bot - avatar