在堆上写文本-这是什么意思?X [count++] = c;

  • 本文关键字:count++ 文本 是什么 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;
有谁能给我解释一下吗?

这是对count进行后增量操作。c的值将赋给x[i],其中i旧的count.

相当于:

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

最新更新