我正在学习一个在堆上写文本的代码:
#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;