// String.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<string>
int main(int argc, char* argv[])
{
using namespace std;
string string_variable;
char a_c_string[] = "This is my C string.";
string_variable = a_c_string; ///合法
//a_c_string = string_variable; //非法
// strcpy(a_c_string , string_variable); //非法
///使用string类的成员函数c_str()执行强制类型转换
strcpy(a_c_string , string_variable.c_str()); ///合法
return 0;
}
string对象和C字符串之间的转换
最新推荐文章于 2021-11-16 14:40:53 发布