我无法理解我的代码出错的地方:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
string str = "";
cin >> str;
remove(str.begin(), str.end(), ' ');
cout << str;
cin.ignore();
}
Run Code Online (Sandbox Code Playgroud)
错误说"'删除':函数不带3个参数(C2660)"
我有这个代码删除std :: string中的空格,它删除空格后的所有字符.所以,如果我有"abc def",它只返回"abc".如何让它从"abc def ghi"变为"abcdefghi"?
#include<iostream>
#include<algorithm>
#include<string>
int main(int argc, char* argv[]) {
std::string input, output;
std::getline(std::cin, input);
for(int i = 0; i < input.length(); i++) {
if(input[i] == ' ') {
continue;
} else {
output += input[i];
}
}
std::cout << output;
std::cin.ignore();
}
Run Code Online (Sandbox Code Playgroud) 我有一个字符串,里面会有多个空白字符,我想用1个空白字符分隔每个单词.如果字符串是"嗨!我的名字是特洛伊,我喜欢华夫饼!",我想修剪它,所以它是"嗨!我的名字是特洛伊,我喜欢华夫饼!".我该怎么做?
我正在考虑隐藏字符串的想法.到目前为止,我有一个函数将字符串中的每个字符转换为十进制值.然后它获取这些值并添加一个隐藏和减去1以显示字符串..然后在隐藏或显示后,它将转换回ASCII字符.
所以这个字符串"Hello"将变为"72 101 108 108 111"然后如果你添加1"73 102 109 109 112",那将成为"Ifmmp".解码你只需减去1.
你可以说这不是很安全......
我需要这种类型的字符串隐藏的想法.
编辑:不要告诉我使用其他库或预先编写的框架.问题是如何在我自己的身上做到这一点.而已.
我有这个代码:
public static Account[] LoadXml(string fileName) {
Account ths = new Account();
// load xml data
// put data into properties/variables
// the xml is in a structure like this:
/*
<accounts>
<account ID="test account">
<!-- account variables here -->
</account>
<account ID="another test account">
<!-- account variables here -->
</account>
</accounts>
*/
}
Run Code Online (Sandbox Code Playgroud)
我如何返回包含这些帐户的数组或集合?
每一个<account ID="test"></account>都是它自己的Account.