gpt4 book ai didi

c++ - 我的 char 数组使用 Visual Studios 2017 C++ 在 318 个字符处截断

转载 作者:太空宇宙 更新时间:2023-11-04 12:53:06 24 4
gpt4 key购买 nike

大家好,我的 char arrays (strings) 有问题不会显示过去的任何内容 318 characters .如果我做 std::string它很好并显示了整个东西......但是如果我尝试使用 std::string.c_str() 将它转换为 char 数组它只产生第一个 318 characters再次。任何帮助将不胜感激。我正在使用 Visual Studio 2017 .实际字符串长度为517chars .

例子...

std::string x = "INSERT INTO oms.Customers (customerFirstName, CustomerMiddleInitial, customerLastName, customerPrefixSuffix, customerCompanyName, customerStreetReference, customerStreetAddress, customerCity, customerState, customerZip, CountryID, customerPhoneNumber, customerEmail, customerIsCompany, customerIsActive) Values('Bill', '
INSERT INTO oms.Customers(customerFirstName, CustomerMiddleInitial, customerLastName, customerPrefixSuffix, customerCompanyName, customerStreetReference, customerStreetAddress, customerCity, customerState, customerZip, CountryID, customerPhoneNumber, customerEmail, customerIsCompany, customerIsActive)Values('Bill', ' ', 'Cosby', '', 'The Cosby Show', 'Studio A', '1818 broadway st', 'Philadelphia', 'PA', '19809', '', '6169875942', 'Bill.Cosby@ididntdoit.com', '', ');SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY];"

但是如果我制作任何类型的字符数组,就像我做的那样

char *y;
y= x.c_str

只有下面会显示

INSERT INTO oms.Customers (customerFirstName, CustomerMiddleInitial, customerLastName, customerPrefixSuffix, customerCompanyName, customerStreetReference, customerStreetAddress, customerCity, customerState, customerZip, CountryID, customerPhoneNumber, customerEmail, customerIsCompany, customerIsActive) Values('Bill', '

如果我这样做 strlen(y)我得到 318 .如果我这样做 x.length()我得到 517 .

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

std::string 可能包含 '\0' 字符,这些字符将被识别为 C 风格的 NUL 终止字符串结束标记strlen(y).
这就是 strlen()std::string::length() 的结果不同的原因。

关于c++ - 我的 char 数组使用 Visual Studios 2017 C++ 在 318 个字符处截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47975310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com