【发布时间】:2014-03-23 16:54:38
【问题描述】:
我正在尝试将 CharArrayPtr 转换为 int 格式,我已经成功地做到了;
std::string str;
for(int i = 0; i < numberofvalues; i++)
{
str = cmemblock[i];
std::stringstream stream;
stream <<str;
int n;
if (!(stream >>n)){
}
cout << n<<endl;
}
但是,我遇到的问题是,如果我要使用cout << str;,它将完全按照 .txt 文件中的显示方式显示字符。不幸的是,转换为int格式后输出不如预期,我将在下面演示;
cout << str;
显示这个;
11
22
33
44
55
66
77
88
99
cout << n;
显示这个;
1
1
1
2
2
2
3
3
3
4
4
4
5
5
5
6
6
6
7
7
7
8
8
8
9
9
9
9
9
9
9
9
9
9
我不完全确定为什么会发生这种情况,但我认为我输入的代码可能没有正确编码以解释新行?
【问题讨论】:
-
我试试看谢谢
-
我无法重现该问题。有关使用您的代码的示例,请参见此处:ideone.com/Xestb9
-
我没有使用 C++11,不确定这是否有区别? Visual Studio 2010 恐怕
标签: c++ arrays char int stringstream