name = nam;这个语句错了,你不能直接将string给char数组复制。方法一:将char name[10];改成string name;方法二:将string变量转换成char[]变量;具体的实例如下:这个由于我们知道string的长度,可以根据length()函数得到,又可以根据下标直接访问,所以用一个循环就可以赋值了。这样的转换不可直接赋值。
加个#include <string>就好了
The sequences controlled by an object of template class basic_string are the Standard C++ string class and are usually referred to as strings, but they should not be confused with the null-terminated C-style strings used throughout the Standard C++ Library. The Standard C++ string is a contai...
The sequences controlled by an object of template class basic_string are the Standard C++ string class and are usually referred to as strings, but they should not be confused with the null-terminated C-strings used throughout the Standard C++ Library. The string class is a container that ...
[Error] cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string<char>}' through '...' 1. 2. 原因 不应该使用printf输出一个String类型的字符串 3.解决办法 使用cout << str ...
switch参数不能用字符串,只能是int型或者char型的 且判断那里应该是==
You can pass a std::basic_string, which converts to a string view. x Null-terminated character string containing the suffix to look for. Return value true if the string ends with the specified suffix; false otherwise. Remarks ends_with() is new in C++20. To use it, specify the /std...
VC++编程时使用ofstream类写文件时,会出现“使用未定义的 class“std::basic_ofstream<char,std::char_traits<char>>””错误,搜素网络说是未“#include <fstream>”,可是明明已经包含了啊。…
类型返回错误
You can pass a std::basic_string, which converts to a string view. x Null-terminated character string containing the suffix to look for. Return value true if the string ends with the specified suffix; false otherwise. Remarks ends_with() is new in C++20. To use it, specify the /std...