草庐IT

str_param_filename

全部标签

c++ - 从函数返回 'c_str'

这是我在网上找到的一个小型图书馆:constchar*GetHandStateBrief(constPostFlopState*state){staticstd::ostringstreamout;//...restofthefunction...returnout.str().c_str()}在我的代码中我这样做:constchar*d=GetHandStateBrief(&post);std::cout现在,起初d包含垃圾。然后我意识到我从函数中获取的C字符串在函数返回时被销毁,因为std::ostringstream是在堆栈上分配的。所以我补充说:returnstrdup(out

c++ - 调用空字符串的 c_str

这个代码片段是正确的还是会导致未定义的行为?std::strings;assert(strlen(s.c_str())==0);如果不是undefinedbehavior,上面的断言会通过吗? 最佳答案 这是完美定义的,断言通过了。c_str()函数将始终返回有效的以零结尾的C字符串。通常会使用empty()来测试空字符串。 关于c++-调用空字符串的c_str,我们在StackOverflow上找到一个类似的问题: https://stackoverflow

c++ - 尝试转换 str 字符串以用于 std::getline 定界符

我正在尝试获取std::string值并将其用作std::getline()函数中的分隔符但无论我做什么,编译器都会给我错误。这就是我想要做的:std::stringstreamss(s);std::stringitem;std::stringdelim="&&=";intssize=delim.size();intnewssize=ssize+1;chardel[SSIZE];//alsoherewhenitrygiveserrorstrcpy(del,delim.c_str());char*delrr[1024]=delim.c_str();//giveserrorwhile(st

c++ - 将 int vector 转换为 str vector

我正在尝试转换vector到vector.使用std::transform我用了std::to_string转换int至string但我不断收到错误消息。这是我的代码#include#include#include#includeintmain(){std::vectorv_int;std::vectorv_str;for(inti=0;i但是我收到了这个错误nomatchingfunctionforcallto'transform'std::transform(v_int.begin(),v_int.end(),v_str.begin(),std::to_string);^~~~~~

c++ - 使用 std::enable_if 作为模板时的默认模板参数。 param.: 为什么可以使用两个仅在 enable_if 参数上不同的模板函数?

在languagereferenceofstd::enable_ifatcppreference包括以下注释NotesAcommonmistakeistodeclaretwofunctiontemplatesthatdifferonlyintheirdefaulttemplatearguments.Thisisillegalbecausedefaulttemplateargumentsarenotpartoffunctiontemplate'ssignature,anddeclaringtwodifferentfunctiontemplateswiththesamesignaturei

python - BeautifulSoup: AttributeError: 'str' 对象没有属性 'copy' 。在 Ubuntu 上工作,在 Windows 上失败

我在使用BeautifulSoup时遇到一个奇怪的错误。这是我正在运行的代码片段:whileTrue:listing_soup=soupify(urlget(page_url))foriinlisting_soup.findAll('div','searchResultContent'):#dosomestuff...这是抛出的异常:Traceback(mostrecentcalllast):File"C:\path\to\script.py",line716,inforiinlisting_soup.findAll('div','searchResultContent'):File"

windows - Perl: "start perl.exe <filename>"与 "perl.exe <filename>"有何不同

我对perl很陌生,我问过一个friend这件事,他说了一些关于“客厅执行”的事情。这是什么意思?编辑:这是在命令提示符下 最佳答案 start使Windows创建一个新的命令提示窗口来运行命令,从而释放原始提示。例如,打开命令提示符并将ping-t8.8.8.8与startping-t8.8.8.8进行比较。 关于windows-Perl:"startperl.exe"与"perl.exe"有何不同,我们在StackOverflow上找到一个类似的问题: h

c++ - GTest 和 GoogleMock EXPECT_CALL 在 Windows 中失败,在 Mac 上通过 char * param

我在我继承的一个项目中有一个看起来与此类似的测试std::stringvalue("teststring");constchar*buffer=value.c_str();EXPECT_CALL(object,foo(_,_,buffer,buffer.size(),_)).WillOnce(Return(0));bar(value);缓冲区是一个char*指向一串数据。我插入了像对象这样的虚拟值,只是为了关注似乎在使用EXPECT_CALL时出现的问题。在此EXPECT_CALL之后,调用方法bar将原始字符串值作为参数,然后在该方法中使用从原始字符串值构建的缓冲区调用foo。此测试

windows - 如何读取注册表资源字符串,例如 "@filename,resource"?

我有一个注册表项,例如LocalizedString=@%programfiles%\InternetExplorer\iexplore.exe,-702除了自定义解析(并使用LoadString)之外,是否有已知的API来提取路径和字符串?然后我有一个默认值,例如(default)="%programfiles%\InternetExplorer\iexplore.exe"(包括双引号,但没有@);Windows如何处理这些东西? 最佳答案 您需要的API函数称为RegLoadMUIStringW.这是一个VistaAPI,因此如

windows - 为什么 Perl 提示 "Unsuccessful stat on filename containing newline"?

我收到一个我不明白的错误。我正在使用File:Find在Windows上使用ActivestatePerl5.8.8递归fylesystem并尝试统计$File::Find::name;所以我不是stat-ing从需要chomp-ing或换行删除的文本文件扫描中获取的文件名。我无法获取文件修改时间,mtimein:my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)=stat($File::Find::name);所以尝试一个-s$File::Find::name给我