Cin()pretype" y"对于用户

时间:2015-08-21 07:29:23

标签: c++ cin

cout << "CONFIRM EXIT [y/n]: ";
cin >> inputChar

控制台应该说:

CONFIRM EXIT [y/n]: y

我见过:

int number(20);
string numStr;
cout << "Please give a number [default = " << number << "]: ";
getline(cin, numStr);
number = ( numStr.empty() ) ? number : strtol( numStr.c_str(), NULL, 0);
cout << number << endl;

^^ User input(cin) - Default value - 通过:组件10

有更好的方法吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

这样的东西?

@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setDefaultViews(Arrays.<View> asList(new MappingJackson2JsonView()));
    return contentViewResolver;
}