String cout自动转到下一行?
打印完it->first.c_str后,代码中的最后一行自动转到下一行,但我想在同一行中打印it->second 如何实现这一点?fgets将换行符保留在行尾。在C++中,使用GETLIN更正常,没有GELIN,这似乎更正常:String cout自动转到下一行?,string,map,iterator,cout,String,Map,Iterator,Cout,打印完it->first.c_str后,代码中的最后一行自动转到下一行,但我想在同一行中打印it->second 如何实现这一点?fgets将换行符保留在行尾。在C++中,使用GETLIN更正常,没有GELIN,这似乎更正常: #include <string> #include <cstring> #include <map> using namespace std; int main() { map<string ,int > m;
#include <string>
#include <cstring>
#include <map>
using namespace std;
int main()
{
map<string ,int > m;
map <string ,int>::iterator it;
char line[64];
int t,n;
m.clear();
for(scanf("%d\n", &n); n--; )
{
fgets(line,64,stdin);
line[32]=0;
m[line]++;
}
for(it=m.begin();it!=m.end();it++)
{
cout<<it->first.c_str()<<it->second<<endl;
}
}