当前位置:网站首页>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 .
边栏推荐
- Usage of insert() in vector
- Two weeks' experience of intermediate software designer in the crash soft exam
- 视频压缩编码和音频压缩编码基本原理
- Redis standalone startup
- SQL quick start
- LeetCode 1552. Magnetic force between two balls
- One hundred questions of image processing (11-20)
- (multiple methods, need to continue to see) 7-11 go deep into the tiger's Den
- @RequestMapping、@GetMapping
- The 116 students spent three days reproducing the ByteDance internal real technology project
猜你喜欢
Shell_ 01_ data processing
ByteDance new programmer's growth secret: those glittering treasures mentors
我走過最迷的路,是字節跳動程序員的腦回路
Chapter 6 datanode
Basic principles of video compression coding and audio compression coding
ByteDance 2022 school recruitment R & D advance approval publicity meeting, students' top 10 issues
Shell_ 04_ Shell script
I'm "fixing movies" in ByteDance
第6章 DataNode
Use JQ to realize the reverse selection of all and no selection at all - Feng Hao's blog
随机推荐
力扣leetcode第 280 场周赛
Simply try the new amp model of deepfacelab (deepfake)
Educational Codeforces Round 122 (Rated for Div. 2)
7-7 ring the stupid bell
字节跳动开源GAN模型压缩框架,算力最高节省97.8%丨ICCV 2021
CMake速成
第6章 DataNode
LeetCode 1636. Sort the array in ascending order by frequency
Shell_ 01_ data processing
LeetCode1556. Thousand separated number
LeetCode 1640. Can I connect to form an array
我在字节跳动「修电影」
谢邀,人在工区,刚交代码,在下字节跳动实习生
~78 radial gradient
Detailed explanation of FLV format
第5章 NameNode和SecondaryNameNode
Chapter 5 yarn resource scheduler
I'm "fixing movies" in ByteDance
JS encapsulates the method of array inversion -- Feng Hao's blog
~83 form introduction