小编tom*_*tom的帖子

如何在Swift 2.0中将字符插入字符串?

此函数接受Int like 324543并返回类似"$ 3245.43"的字符串

我的尝试在下面,但Swift 2不喜欢 atIndex: 0

我如何将字符插入字符串呢?

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
}
Run Code Online (Sandbox Code Playgroud)

swift2

6
推荐指数
1
解决办法
5759
查看次数

为什么可以使用'string'作为变量的名称

我是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

c++ string

0
推荐指数
1
解决办法
321
查看次数

标签 统计

c++ ×1

string ×1

swift2 ×1