当前位置:网站首页>After the subscript is used to assign a value to the string type, the cout output variable is empty.
After the subscript is used to assign a value to the string type, the cout output variable is empty.
2022-07-06 16:53:00 【Flower dog fdog】
When writing to create a folder today , No matter how you create it , Revise over and over again , Make sure the mistake is string Type variables .
Look at the code below
// The code in this function , The argument to the function is string fileurl_s
int len = fileurl_s.length();
std::string fileurl_s_cy;
for(int i =0;i<len;i++)
{
fileurl_s_cy[i]=fileurl_s[i];
if(fileurl_s_cy[i]=='/' || fileurl_s_cy[i]=='\\')
{
if (0 != access(fileurl_s_cy.c_str(), 0))
{
mkdir(fileurl_s_cy.c_str(),0); // return 0 Indicates that the creation was successful ,-1 It means failure
}
}
}
The function of this code is to create folders , And subfolders , According to the parameters , Skip if there is , Nothing creates
But I found that I couldn't create folders at all
I try to output fileurl_s_cy[i], It can output the characters I want normally
But when I output fileurl_s_cy There's something wrong with it ,fileurl_s_cy From beginning to end, it is empty , Length is also empty , As a result, the folder cannot be created normally
It can output normally fileurl_s_cy[i], But it cannot output normally fileurl_s_cy, I thought it was ’\0’ The problem of , It's useless to add discovery ,fileurl_s_cy The overall length is still 0
I can use std::stringfileurl_s_cy = “www/ccccc” This form normally creates folders , However, the subscript assignment method cannot be used
After Baidu , I learned it because of the statement fileurl_s_cy There was no room to open up , So it can't be used
The strange thing is the output fileurl_s_cy[i] I didn't report an error .
The solution is as follows :
The declaration is changed to std::string fileurl_s_cy(len,’\0’);
In this way, subscript assignment can be used normally , Output and overall output
Afraid to forget , Record with this .
边栏推荐
- Simple records of business system migration from Oracle to opengauss database
- 提交Spark应用的若干问题记录(sparklauncher with cluster deploy mode)
- ~84 form supplement
- The concept of spark independent cluster worker and executor
- Solve the single thread scheduling problem of intel12 generation core CPU (II)
- Educational Codeforces Round 122 (Rated for Div. 2)
- 字节跳动技术新人培训全记录:校招萌新成长指南
- Chapter III principles of MapReduce framework
- The most lost road I have ever walked through is the brain circuit of ByteDance programmers
- 力扣leetcode第 280 场周赛
猜你喜欢

Spark独立集群动态上线下线Worker节点

LeetCode 1560. The sector with the most passes on the circular track

Shell_ 06_ Judgment and circulation

~74 JD top navigation bar exercise

~82 style of table

~84 form supplement

字节跳动技术面试官现身说法:我最想pick什么样的候选人

我在字节跳动「修电影」

Error occurred during initialization of VM Could not reserve enough space for object heap

~Introduction to form 80
随机推荐
Erlang installation
Educational Codeforces Round 122 (Rated for Div. 2)
~Introduction to form 80
7-4 harmonic average
The most lost road I have ever walked through is the brain circuit of ByteDance programmers
README. txt
LeetCode 1641. Count the number of Lexicographic vowel strings
字节跳动新程序员成长秘诀:那些闪闪发光的宝藏mentor们
图像处理一百题(11-20)
解决Intel12代酷睿CPU【小核载满,大核围观】的问题(WIN11)
第5章 消费者组详解
Cartesian tree (modified)
Spark独立集群Worker和Executor的概念
~87 animation
LeetCode 1551. Minimum operand to make all elements in the array equal
两个礼拜速成软考中级软件设计师经验
Chapter 1 overview of MapReduce
Record the error reason: terminate called after throwing an instance
Solr new core
字节跳动开源GAN模型压缩框架,算力最高节省97.8%丨ICCV 2021