C++ Numbers and Strings
π’π§΅ C++ Numbers and Strings
C++ mein numbers (int, float, double) aur strings (text) ko saath use karna common hai.
Neeche print, concatenate, convert, inputβsab clear examples ke saath samjhaaya gaya hai.
πΉ 1. Numbers vs Strings (Basic Difference)
aβ number (math possible)bβ string (text)
πΉ 2. Print Number with String
Output:
πΉ 3. Concatenate String with Number β (Directly)
β Correct (Use to_string)
πΉ 4. Convert Number β String (to_string)
πΉ 5. Convert String β Number
πΈ stoi (string β int)
πΈ stof (string β float)
πΈ stod (string β double)
πΉ 6. Math with Converted Strings
πΉ 7. User Input: Number + String
πΉ 8. String with Digits (Still String!)
To calculate:
β Common Mistakes
β Correct:
π Summary
Numbers β math operations
Strings β text operations
to_string(): number β stringstoi / stof / stod: string β numberDirect string + number β (convert first)
