⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threetolong.cpp

📁 datastucutre and algorithms, application, in C
💻 CPP
字号:

// convert characters 0, 1 and 2 of a string into a long

#include <iostream>
#include <string>

using namespace std;


long threeToLong(string s)
{// Assume s.length() >= 3.
   // leftmost char
   long answer = s.at(0);

   // shift left 8 bits and add in next char
   answer = (answer << 8) + s.at(1);

   // shift left 8 bits and add in next char
   return (answer << 8) + s.at(2);
}

// test program 
void main(void)
{
    string s = "abc";
    for (int i = 0; i < 3; i++)
       cout << s.at(i) << " " << ((int) s.at(i)) << endl;

    cout << threeToLong(s) << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -