c++如何取出string中的第一个字符?
来源:百度知道 编辑:UC知道 时间:2024/05/17 17:38:30
string s;
char c;
我想把s的第一个字符赋给c,应当怎样操作?
char c;
我想把s的第一个字符赋给c,应当怎样操作?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
char c;
cin >> s;
c = s.at(0);
cout << c << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s="helloworld";
int index=0;
while(s[index]!='\0')
cout<<s[index++];
return 0;
}
c=s[0];
c=s.str[0]
c=string[0]