English 中文(简体)
2008年视觉演播室2次指挥线论点的逐字表述
原标题:2 byte representation of command line arguments in Visual Studio 2008

在2008年视觉演播室撰写的简单的C++申请中处理指挥线论点时,我有问题。 我写了以下法典:

#include <iostream>

using namespace std;

int _tmain(int argc, char **argv)
{
    char* c = *argv;    

    for(int i=0; i< argc ; ++i) 
    {
        cout << argv[i] << endl;
    }

    int a;
    cin >> a;

    return 0;    
}

我的问题是,每个指挥线论点的头一种特性只写到<编码>cout。

I identified the cause to be that the characters in the command line arguments are represented as 2 bytes, making every other 1 byte char contain only zeros, i.e .

我的问题是,为什么发生这种情况? 从在净值的样本中发现的样本中发现的样本中可以做的是书面的。 此外,是否有办法强迫提出1个特有代表的论点的性质?

我希望我的问题足够清楚。

最佳回答

您的<代码>_tmain正在接收UTF-16特性,该特性在拉丁文本中各有0。 你们把他们解释为单一特质。 你们需要将其解释为广泛。

我这样说:

#include <iostream>

using namespace std;

int wmain(int argc, wchar_t* argv[])
{
  for(int i=0; i<argc; ++i) 
  {
    wcout << argv[i] << endl;
  }

  int a;
  wcin >> a;

  return 0;
}

如果你不想使用UTF-16,那么你可以遵守char。 类似:

int main(int argc, char* argv[])
{
  for(int i=0; i<argc; ++i) 
  {
    cout << argv[i] << endl;
  }

  int a;
  cin >> a;

  return 0;
}

注<代码>main功能的命名变更。 在管理系统世界,wmain 收到wchar_t*main。 www.un.org/spanish/ga/president

如果您转向<代码>char* 之后,您还应更新项目组合,以针对甲基溴消费控制而不是统法协会。

更多关于管理编辑的主要职能处理的信息见:

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签