首页 > 解决方案 > 在堆上写文本 - 这是什么意思?x[计数++] = c;

问题描述

我正在研究在堆上写入文本的代码:

#include <iostream>
using namespace std;

int main() {
    
    char c;
    int count{0},d{0};
    char *x;
    x = new char[1000];
    if(x != NULL){
        cout << "enter the text,ending with by eof marker" << endl;
        for(count=0; count!=cin.eof()&&count<1000;){
            cin >> c;
            if(!cin.eof())
            x[count++] = c;
                
        }
        for(int d=0; d<count;d++)
        cout << *(x+d);
        cout << "end of text" << endl;
    }

我在理解这个片段时遇到了问题:

x[count++] = c;

谁能给我解释一下?

标签: c++

解决方案


这是在做. count的值c将被分配给x[i],其中i是 的count

它相当于:

x[count] = c;
count = count + 1;

推荐阅读