c++中定义了string类字符数组,如何输出string里单个字符(比如第二个字符)。

2025-01-03 23:25:01
推荐回答(3个)
回答1:

直接取就可以了。例如:
string name="hello";
name[0];//这里name[0]就是第一个字符'h'

回答2:

d
Press any key to continue

#include
#include
using namespace std;
main()
{
string aa="123asdf";
cout<}

回答3:

/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/

#include
#include

void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}

Output
String = Hello world from strcpy and strcat!