此函数接受Int like 324543并返回类似"$ 3245.43"的字符串
我的尝试在下面,但Swift 2不喜欢 atIndex: 0
我如何将字符插入字符串呢?
Run Code Online (Sandbox Code Playgroud)func stylizeCents (cent: Int) -> String { var styledCents = String(cent) let dollarSign : Character = "$" let dot : Character = "." let count = styledCents.characters.count styledCents.insert(dollarSign, atIndex: 0) // error styledCents.insert(dot, atIndex: count-1) // error }
我是C++的初学者,我正在做一些Stroustrup的练习Programming Principles And Practice Using C++.这个练习要我试验合法和非法的名字.
void illegal_names()
{
// the compiler complains about these which made sense:
// int double =0;
// int if =0;
// int void = 0;
// int int = 0;
// int while =0;
// string int = "hello";
//
// however, this is legal and it runs without a problem:
double string = 0.0;
cout << string<< endl;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,什么使得string与其他类型不同?是否还有其他特殊类型string?