Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第5章 字符串 部分有问题 #48

Open
benblueba opened this issue May 23, 2020 · 0 comments
Open

第5章 字符串 部分有问题 #48

benblueba opened this issue May 23, 2020 · 0 comments

Comments

@benblueba
Copy link

5.1.3 字符串 104页 提示5-5上方
原文是:

例如,C++的cin/cout可以直接读写string类型,却不能读写字符数组;string类型还可以像整数那样“相加”……

而在下面那份“输出每行所有整数之和”的代码中,有这样几行代码:

while(getline(cin,line)) {
  int sum = 0, x;
  stringstream ss(line);
  while(ss >> x) sum += x;
  cout << sum << "\n";
}

注意这里:

  cout << sum << "\n";

"\n"本身就是一个“只有一个字符”的字符数组,而能写到cout里。这不与上面“不能读写字符数组”矛盾吗?仔细查一查iostream的资料,可以发现它们可以读写char*或者 char[]
建议作者改一下。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant