64,646
社区成员
发帖
与我相关
我的任务
分享
wstring wstr;
vector<wstring> strColl;
vector<wstring>::iterator iter;
vector<wstring>::const_iterator const_iter;
// TCHAR buffer[2048];
wcout << L"Enter a string: ";
// while (wcin.getline(buffer, sizeof(buffer)-1))
while(getline(std::wcin, wstr))
{
wcout << wstr << endl;
strColl.push_back(wstr);
}
wcout << "print vector<string>: \n";
for (const_iter = strColl.begin(); const_iter != strColl.end(); ++const_iter)
{
wcout << *const_iter << endl;
}
cout << endl;
[Quote=引用 4 楼 的回复:]
// aaa.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <afx.h>
#include <afxdb.h>
#include <iostream>
#include <vector>
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
locale("chs");
vector<wstring> strColl;
vector<wstring>::iterator iter;
vector<wstring>::const_iterator const_iter;
TCHAR buffer[2048];
wcout << "Enter a string: ";
while (wcin.getline(buffer, sizeof(buffer)-1))
{
wcout << "string== " << buffer << endl;
strColl.push_back(buffer);
}
wcout << "print vector<string>: \n";
for (const_iter = strColl.begin(); const_iter != strColl.end(); ++const_iter)
{
wcout << (*const_iter).c_str() <<"\n";
}
wcout << endl;
}
}