小编Chr*_*ris的帖子

在特定的内存地址创建新的C++对象?

在C++中是否可以在特定的内存位置创建新对象?我有一个共享内存块,我想在其中创建一个对象.这可能吗?

c++ memory location pointers object

37
推荐指数
2
解决办法
3万
查看次数

C++ stringstream返回额外的字符?

我一直在尝试使用C++ stringstream类来做一些相对简单的字符串操作,但是我遇到了get()方法的问题.出于某种原因,每当我按字符提取输出字符时,它会附加最后一个字母的第二个副本.

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
   stringstream ss("hello");
   char c;

   while(!ss.eof()) {
      ss.get(c);
      cout << "char: " << c << endl;
   }
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

该程序的输出是:

char: h
char: e
char: l
char: l
char: o
char: o
Run Code Online (Sandbox Code Playgroud)

任何帮助,你可以给我这个将不胜感激.

c++ string stream sstream

2
推荐指数
1
解决办法
3254
查看次数

标签 统计

c++ ×2

location ×1

memory ×1

object ×1

pointers ×1

sstream ×1

stream ×1

string ×1