Convert String to size_t in C++ Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report To convert String to size_t in C++ we will use stringstream, It associates a string object with a stream allowing you to read from the string as if it were a stream (like cin). We must include the stream header file in order to use stringstream. When parsing input, the stringstream class comes in quite handy. Syntax: std :: stringstream stream(string_name) Example: C++ // C++ Program to declare a string variable without using stringstream. #include <iostream> using namespace std; int main() { string s1 = "Hello Geek"; cout << s1 << endl; string s2; cin >> s2; cout << s2 << endl; return 0; } Output: Hello Geek GeeksforGeeks Example: C++ // C++ Program to convert the string to size_t using // stringstream. #include <iostream> #include <stream> #include <string> using namespace std; int main() { string str = "246810"; // breaking words stringstream stream(str); // associating a string object with a stream size_t output; // to read something from the stringstream object stream >> output; cout << output << endl; return 0; } Output: 246810 Comment More infoAdvertise with us Next Article Must Coding Questions - Company-wise A anuragsingh1022 Follow Improve Article Tags : Technical Scripter C++ Technical Scripter 2022 C Conversion Programs Practice Tags : CPP Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like