如何使用指针获取列表的大小?我有以下代码.我把几个整数放在里面,后来试图得到列表的大小.
#include <iostream>
#include <list>
using namespace std;
int main ()
{
list<int>* t;
for (int i=1; i<10; ++i)
{
t->push_back(i*10);
}
cout<<"size:\t"<<t->size()<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我是C++的初学者,并尝试运行一些初学者代码.我有以下文件,
myTest.h
////////
#ifndef __myTest_h__
#define __myTest_h__
#include <string>
using std::string;
class myTest{
public:
int main(int, char const**);
};
#endif // __myArray_h__
myTest.cpp
//////////
#include<iostream>
#include<string>
#include "myTest.h"
using namespace std;
int myTest::main(int argc, char const *argv[])
{
std::cout<< "Hello World/n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用该命令从Mac OS中的终端运行时,我在终端中g++ myTest.cpp -o myTest.out收到以下错误,
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 …Run Code Online (Sandbox Code Playgroud) 我有一些代码使用Spring MVC项目生成加密货币钱包.
@RequestMapping(value = "/generateAddress", method = RequestMethod.POST)
public ResponseEntity<WalletInfoWrapper> generateAddress(@RequestParam("walletName") String walletName,
@RequestParam("currencyName") String currencyName, HttpServletRequest request) {
String wallet_Name = request.getParameter("walletName");
String currency_Name = request.getParameter("currencyname");
System.out.println("wallet_Name = " + wallet_Name + " , currency_Name = " + currency_Name);
// return if the wallet name or the currency is null
if (Objects.isNull(wallet_Name) || Objects.isNull(currency_Name)) {
return new ResponseEntity<WalletInfoWrapper>(HttpStatus.NOT_ACCEPTABLE);
}
WalletInfo walletInfo = walletService.generateAddress(wallet_Name);
if (Objects.isNull(walletInfo)) {
return new ResponseEntity<WalletInfoWrapper>(HttpStatus.NOT_ACCEPTABLE);
}
WalletInfoWrapper walletInfoWrapper = new WalletInfoWrapper();
walletInfoWrapper.setName(walletInfo.getName());
return new ResponseEntity<WalletInfoWrapper>(walletInfoWrapper, …Run Code Online (Sandbox Code Playgroud) 我使用Spring Boot和WebSocket项目,当我试图保持(保存)输出消息时,我收到错误.我打印了要提供的实体,
Inout MessageMessage{id=null, from='Mark', text='I travel to Brazil'}
Output MessageOutputMessage{id=null, from='Mark', message='I travel to Brazil', topic='Travel', time=Tue Nov 14 10:53:06 BDT 2017}
Hibernate: insert into output_message (from, message, time, topic) values (?, ?, ?, ?)
Run Code Online (Sandbox Code Playgroud)
错误消息如下所示,
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] …Run Code Online (Sandbox Code Playgroud) 什么是一个转换的最佳方式"PascelCase"串,像下划线分隔全部大写"Pascel_CASE"。我写了这个有效的代码:
private static String pascelCaseToUpperCaseSeparatedByUnderscore(String s) {
String[] values = s.split("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])");
for (int i = 0, len = values.length; i < len; i++) {
values[i] = values[i].toUpperCase();
}
return String.join("_", values);
}
Run Code Online (Sandbox Code Playgroud)
但是,有没有更好的方法说,使用库来做到这一点?