小编sm1*_*m15的帖子

删除元音,除非它是单词的开头

我试图删除字符串中元音的出现,除非它们是单词的开头.所以例如输入"The boy is about to win" 应该输出.这Th by is abt t wn是我到目前为止所拥有的.任何帮助,将不胜感激!

def short(s):
vowels = ('a', 'e', 'i', 'o', 'u')
noVowel= s
toLower = s.lower()
for i in toLower.split():
    if i[0] not in vowels:
        noVowel = noVowel.replace(i, '')        
return noVowel
Run Code Online (Sandbox Code Playgroud)

python

3
推荐指数
1
解决办法
780
查看次数

如何从方法中打印指针的值?

基本上我有两个函数,主要有一个指针指向c(可变内存地址).我的问题是为什么我不能从print函数调用指针并打印出字符串.另外,如果我有一个类文件并想从那里调用指针(不向print函数添加参数),该怎么办?

#include <iostream>
#include <string>
using namespace std;

static int print(){
    cout << *pointer;
}

int main() {
    string c = "Hello World!";
    string *pointer = new string;
    pointer = &c;
    print();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers

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

标签 统计

c++ ×1

pointers ×1

python ×1