如何将文本指定为整数c ++?

时间:2015-03-15 20:51:08

标签: c++ integer

我是c ++编程的新手。我怎么能这样做?...

int question1;

question1: "What is your name?";

将文本值设置为整数?

1 个答案:

答案 0 :(得分:1)

#include <string>
#include <iostream>

int main( )
{
    std::string name;

    std::cout << "What is your name?: " << std::endl;
    std::cin >> name;
    std::cout << "Your Name: " << name << std::endl;
    std::cin.get( );
    return 0;
}

只需以字符串形式阅读输入内容。