我正在编写一个程序来检查输入的短语是否是回文。 在MacBook Pro上使用Xcode编译可以正常工作。在zyBooks网站上编译时返回错误。
如何更新我的代码以解决此问题?
我的代码是:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string userInput, palindromeCheck, reversedInput;
getline(cin, userInput);
palindromeCheck = userInput;
remove(palindromeCheck.begin(), palindromeCheck.end(), ' ');
palindromeCheck.erase(palindromeCheck.size() - 3, palindromeCheck.size());
int temp = 1;
while (temp < palindromeCheck.size() + 1)
{
reversedInput += palindromeCheck.at(palindromeCheck.size() - temp);
++temp;
}
if (reversedInput == palindromeCheck)
{
cout << userInput << " is a palindrome";
}
else
{
cout << userInput << " is not a palindrome";
}
cout << endl;
return 0;
}
zyBooks的完整错误代码如下:
main.cpp: In function ‘int main()’:
main.cpp:14:33: error: cannot convert ‘std::__cxx11::basic_string<char>::iterator’ {aka ‘__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >’} to ‘const char*’
14 | remove(palindromeCheck.begin(), palindromeCheck.end(), ' ');
| ~~~~~~~~~~~~~~~~~~~~~^~
| |
| std::__cxx11::basic_string<char>::iterator {aka __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >}
In file included from /usr/include/c++/9/cstdio:42,
from /usr/include/c++/9/ext/string_conversions.h:43,
from /usr/include/c++/9/bits/basic_string.h:6493,
from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from main.cpp:1:
/usr/include/stdio.h:178:32: note: initializing argument 1 of ‘int remove(const char*)’
178 | extern int remove (const char *__filename) __THROW;
| ~~~~~~~~~~~~^~~~~~~~~~
main.cpp:20:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
20 | while (temp < palindromeCheck.size() + 1)
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
答案 0 :(得分:0)
不包含HTML file
<div id="username">@twostraws</div>
Swift File
let webView = WKWebView()
override func viewDidLoad() {
super.viewDidLoad()
if let url = Bundle.main.url(forResource: "myHTML", withExtension: "html") {
webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
}
webView.evaluateJavaScript("document.getElementById('username').innerText") { (result, error) in
if let result = result {
print("what is in div",result)
}
else {
print("didn't find it")
}
}
override func loadView() {
self.view = webView
}
库的A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=TypeError: null is not an object (evaluating 'document.getElementById('username').innerText'), WKJavaScriptExceptionColumnNumber=32, WKJavaScriptExceptionSourceURL=about:blank, NSLocalizedDescription=A JavaScript exception occurred})
函数可删除系统中的现有文件。该函数的函数签名如下:
remove()
另一方面,在使用algorithm.h
之后,您现在可以将int remove(const char *_Filename)
用于迭代器:
algorithm.h
问题在于该函数没有接受remove()
对象_FIter remove<_FIter, _Tp>(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__value)
和std::string
作为参数的函数重载。