string line;
int input;
stringstream linestream;
cout << "\nEnter integer: ";
getline(cin,line);
cout << "\nNumber is << line;
当我正在尝试打印String行时:我得到输入的no加上一些未知数字 例如。如果我输入951输出将是951 289792一些垃圾 我不想使用整数。并且没有cin&gt;&gt;声明b4此代码
答案 0 :(得分:0)
适合我,
//stringstream linestream;
//extract to string
#include <iostream>
#include <string>
main ()
{
std::string line;
//int input;
std::cout << "Enter integer: ";
std::getline(std::cin,line);
std::cout << "Number is " << line << std::endl;
return 0;
}