c++学习零碎知识点

                         写些学习c++过程中遇到的疑惑,方便以后查阅

1> const char *p[4] ,p是一个包含四个元素的一维数组,元素的类型是const char * 

    const char *p="hello";
    const char * q[3]={
        "hello",
        "nice",
        "day"
    };  
    cout<<p<<" at "<<&p<<" "<<*(&p)<<endl;
    cout<<(void *)q<<" "<<q<<*q<<endl;
    cout<<q[0]<<" "<<&q[0]<<endl;
    cout<<q[1]<<" "<<&q[1]<<endl;
    cout<<(void *)"hello"<<" "<<(void *)"nice"<<"  "<<(void *)"day"<<endl;
    cout<<(void *)q[0]<<" "<<(void *)q[1]<<" "<<(void *)q[2];

输出:
hello at 0x7ffc7c7e4798 hello
0x7ffc7c7e47a0 0x7ffc7c7e47a0hello
hello 0x7ffc7c7e47a0
nice 0x7ffc7c7e47a8
0x560de9ce8005 0x560de9ce800b  0x560de9ce8010
0x560de9ce8005 0x560de9ce800b 0x560de9ce8010%  

//“hello”为静态字符串,可以理解为常量,q[0]中存储的实际上是其地址,而&q[0]输出的是q[0]指针本身的地 址。想要查看字符串实际的地址需要转换下,用(void*)强制转换。cout<<q[0]猜想是进行了转换(应该是函数重载)然后字符串存储多加了个‘\0’

2>刚好遇到C++中测试输入的单词中有多少个元音单词和铺音单词和其他单词问题顺便遇到个  无法打开“istream.tcc”: 无法读取文件'/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/istream.tcc' (Error: 无法解析不存在的文件"/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/istream.tcc")。  //cout cin单步调试的时候会直接进入cout cin 所以遇到这个的时候需要F10单步跳过。读书不认真听啊。这个好像反编译的时候也会有这个思想。

#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;

int main()
{
    char ch=' ';
    char str[20]={};//务必记住先初始化
    int num1=0,num2=0,num3=0;
    std::cout<<"enter :";
    ch=cin.get();
    int k=0,len=0;
    while(ch!='q'){
        if(ch!=' '){
        str[k] = ch;
        ++k;
        if(isalpha(ch))++len;
        }else if(len==k){
        if(str[0]=='a'||str[0]=='e'||str[0]=='i'||str[0]=='o'||str[0]=='u')++num1;
        else ++num2;
        len = 0;//重置长度
        k = 0;
        memset(str,'\0',20);//重置数组
        }else if (len!=0&&ch==' '){
            ++num3;
            k=0;
            len=0;
            memset(str,'\0',20);
        }
       ch=cin.get();
    }
    std::cout<<num1<<"  "<<num2<<"  "<<num3<<std::endl;
    return 0;
}

3>    void set(stringy &sy,const char (&a)[20]);         字符串数组的引用。                                       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值