c++如何取出string中的第一个字符?

string s;
char c;
我想把s的第一个字符赋给c,应当怎样操作?

第1个回答  2008-11-12
#include <iostream>
#include <string>
using namespace std;

int main()
{
string s;
char c;
cin >> s;

c = s.at(0);
cout << c << endl;

return 0;
}
第2个回答  推荐于2017-09-14
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s="helloworld";
int index=0;
while(s[index]!='\0')
cout<<s[index++];
return 0;
}
第3个回答  2008-11-12
c=s.str[0]
第4个回答  2008-11-12
c=string[0]本回答被提问者采纳
第5个回答  2008-11-12
c=s[0];