运算符++
应该等价于+ 1
,那么为什么下面的例子会产生不同的结果呢?
#include <iostream>
#include <string>
int main()
{
int i, n=25;
std::string s1="a", s2="a", s1p="", s2p="";
for (i=0;i<=n;i++)
{
s1p += s1;
s1 = s1.at(0) + 1;
s2p += s2;
s2 = s2.at(0)++;
}
std::cout << "s1p = " << s1p << "\n" << "s2p = " << s2p << "\n";
return 0;
}
Ouput:
s1p = abcdefghijklmnopqrstuvwxyz
s2p = aaaaaaaaaaaaaaaaaaaaaaaaaa