【发布时间】:2020-05-17 10:29:50
【问题描述】:
如果我输入的字符串大于设置的大小,我需要某种错误处理程序。
cout << "Enter long of the string" << endl;
cin >> N;
char* st = new char[N];
char* st1 = new char[N];
for (int i = 0; i < N; ++i) {
*(st1 + i) = ' ';
}
cout << "Enter string in the end put 0,without whitespace in the end." << endl;
cin.getline(st, N, '0');
【问题讨论】:
-
为什么不使用 std::string?
-
接下来我需要逐字拆分字符串,而不是用旧字符串中从 X 到 Y 的单词创建一个新字符串。如果使用 char 数组,我认为它更简单。
-
你认为你可以用 char 数组做什么,而你不能用
std::string做什么?
标签: c++ c++11 visual-c++