首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

istream 之 getline解决方法

2012-05-03 
istream 之 getline想让IO流支持UNICODE ,这么写代码。为何跑起来,一闪而过?求解,代码如下,console applica

istream 之 getline
想让IO流支持UNICODE ,这么写代码。为何跑起来,一闪而过?求解,代码如下,console application 选择支持MFC。

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;


[解决办法]
单步调试下呢。
[解决办法]

C/C++ code
// 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;    }} 

热点排行