我有此代码段,目的是获取系统PATH变量中的路径列表并将它们打印在CMD控制台上;打印到控制台时在字符之间出现额外符号
#include <iostream>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
int main()
{
string path = getenv("PATH");
string tempo = "";
list<string> pathList;
for(size_t n = 0; n < path.size(); n++)
{
char delimiter = ';';
if(path.at(n) == delimiter)
{
if(!tempo.empty())
{
pathList.push_back(tempo);
}
tempo.clear();
}
else{
char aChar = path.at(n);
tempo.append(&aChar);
}
}
list<string>::iterator listIter;
for(listIter = pathList.begin(); listIter != pathList.end(); listIter++)
{
cout << *listIter << endl;
}
return 0;
}
我每次编译和CMD控制台我得到类似这样的输出线路上运行;
C►■":►■"\►■"P►■"y►■"t►■"h►■"o►■"n►■"2►■"6►■"\►■"S►■"c►■"r►■"i►■"p►■"t►■"s►■"
难道是内存损坏吗?我究竟发现了什么? 上午在Windows 7 64位,编译使用MinGW的(G ++ 4.8)]
这是* waaaaay *太漂亮是 “腐败”! – user2864740