首页 > 代码库 > C++编程题

C++编程题

1、不用系统提供的字符串转int的功能,将一个字符串转换为对应的值

#include <iostream>using namespace std;static int StringToInt(string s){	int sum;	for(int i=0;i<s.length();i++)	{		sum = sum * 10 + (s[i]-‘0‘);	}	return sum;}int main() {	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!	int sum;	string s = "hello";	sum = StringToInt(s);	cout<<sum<<endl;	return 0;}

C++编程题