如何解决将 char** 转换为 int C++
所以我有一个符号数组,其中包含另一个符号数组(如果我没猜错的话)。我需要做的是更改第三个元素 (words[2]
)。这第三个元素肯定是一个数字。我必须将这个数字增加 15%。因此,我需要将 words[2]
转换为 int
?
功能:
void create(char* str) {
char** words = new char* [strlen(str)];
int count = 0;
for (char* part = strtok(str," "); part != NULL; part = strtok(NULL," ")) {
words[count] = _strdup(part);
count++;
}
cout << "\nNew sentence with edited values:" << endl;
words[2] = words[2] + ((int)words[2] / 100) * 15; //the main problem as I guess
for (int i = 0; i < count; i++) {
printf("%s ",words[i]);
}
cout << endl;
delete[] words;
}
完整代码:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string.h>
using namespace std;
void create(char*);
void main() {
const int maxLength = 100;
char* str = new char[maxLength];
cout << "Enter sentence:\n";
cin.getline(str,maxLength);
create(str);
delete[] str;
}
void create(char* str) {
char** words = new char* [strlen(str)];
int count = 0;
for (char* part = strtok(str," ")) {
words[count] = _strdup(part);
count++;
}
cout << "\nNew sentence with edited values:" << endl;
words[2] = words[2] + ((int)words[2] / 100) * 15;
for (int i = 0; i < count; i++) {
printf("%s ",words[i]);
}
cout << endl;
delete[] words;
}
无法使用 string
执行此操作。实际上,这是我大学的作业,不使用string
是条件
解决方法
您需要将 <form action="{{ url_for('questions') }}" method="GET">
<button type="submit" name="sort" value="latest" class="btn">Latest</button>
<button type="submit" name="sort" value="oldest" class="btn">Oldest</button>
<button type="submit" name="sort" value="names" class="btn">Name</button>
</form>
转换为 char*
,如下所示。 int
无法投射
(int)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。