当前位置:网站首页>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 .
边栏推荐
- 100张图训练1小时,照片风格随意变,文末有Demo试玩|SIGGRAPH 2021
- LeetCode 1557. The minimum number of points that can reach all points
- ~84 form supplement
- Shell_ 05_ operator
- CMake速成
- LeetCode 1552. Magnetic force between two balls
- 【锟斤拷】的故事:谈谈汉字编码和常用字符集
- Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
- ~74 JD top navigation bar exercise
- The concept of spark independent cluster worker and executor
猜你喜欢
Gridhome, a static site generator that novices must know
~68 Icon Font introduction
Simply try the new amp model of deepfacelab (deepfake)
字节跳动多篇论文入选 CVPR 2021,精选干货都在这里了
Solve the problem of intel12 generation core CPU [small core full, large core onlookers] (win11)
两个礼拜速成软考中级软件设计师经验
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
JS encapsulates the method of array inversion -- Feng Hao's blog
Shell_ 03_ environment variable
Shell_ 02_ Text three swordsman
随机推荐
ffmpeg命令行使用
Research Report on market supply and demand and strategy of China's tetraacetylethylenediamine (TAED) industry
Shell_ 05_ operator
@RequestMapping、@GetMapping
LeetCode 1640. Can I connect to form an array
Shell_ 00_ First meeting shell
~72 horizontal and vertical alignment of text
One hundred questions of image processing (1-10)
~75 background
LeetCode 1551. Minimum operand to make all elements in the array equal
LeetCode 1560. The sector with the most passes on the circular track
Error: case label `15 'not within a switch statement
Introduction to microservices
Usage of insert() in vector
Simply try the new amp model of deepfacelab (deepfake)
Story of [Kun Jintong]: talk about Chinese character coding and common character sets
【锟斤拷】的故事:谈谈汉字编码和常用字符集
Educational Codeforces Round 122 (Rated for Div. 2)
Spark independent cluster dynamic online and offline worker node
Solve the single thread scheduling problem of intel12 generation core CPU (II)