To convert a string to an integer, you can use the std::stoi function, and to convert a string to a floating-point number, you can use the std::stof or std::stod functions.
Here's an example code snippet:
#include <iostream>
#include <string>
int main() {
std::string numberStr;
std::cout << "Enter a number: ";
std::getline(std::cin, numberStr);
int numberInt = std::stoi(numberStr);
float numberFloat = std::stof(numberStr);
std::cout << "Integer: " << numberInt << std::endl;
std::cout << "Float: " << numberFloat << std::endl;
return 0;
}
In this example, std::stoi converts the string to an integer, while std::stof converts the string to a floating-point number.