当前位置: 首页>>代码示例>>C++>>正文


C++ Convert类代码示例

本文整理汇总了C++中Convert的典型用法代码示例。如果您正苦于以下问题:C++ Convert类的具体用法?C++ Convert怎么用?C++ Convert使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Convert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{

long numberToConvert;
int baseToConvert;

cout<<"This Program will convert any number of any base (<10) to its decimal equivalent"<<endl;

cout<<"Enter number: ";
cin>>numberToConvert; //Reading the number to be converted

cout<<"Enter Base (between 2 and 10): ";
cin>>baseToConvert; //reading the base of the number to be converted

Convert convertNumber;
if(convertNumber.checkValidity(numberToConvert,baseToConvert))/// check if the number-base is valid
{ 
	cout<<"Decimal number equivalent is:"<<convertNumber.convertToDecimal()<<endl; // print the decimal equivalent
} //end if
else
{
	cout<<"Invalid number or/and base entered"<<endl;
} //end else

return 0;
} // end main
开发者ID:bharatdarapu,项目名称:Object-Oriented-Approach-in-C-plus-plus,代码行数:26,代码来源:main.cpp

示例2: assert

vector<unsigned short>
IceUtilInternal::toUTF16(const vector<Byte>& source)
{
    vector<unsigned short> result;
    if(!source.empty())
    {

#ifdef ICE_HAS_CODECVT_UTF8
    assert(sizeof(Char16T) == sizeof(unsigned short));

    typedef wstring_convert<codecvt_utf8_utf16<Char16T>, Char16T> Convert;

    Convert convert;

    try
    {
        Convert::wide_string ws = convert.from_bytes(reinterpret_cast<const char*>(&source.front()),
                                                     reinterpret_cast<const char*>(&source.front() + source.size()));

        result = vector<unsigned short>(reinterpret_cast<const unsigned short*>(ws.data()),
                                        reinterpret_cast<const unsigned short*>(ws.data()) + ws.length());
    }
    catch(const std::range_error& ex)
    {
        throw IllegalConversionException(__FILE__, __LINE__, ex.what());
    }

#else
    convertUTF8ToUTF16(source, result);
#endif
    }
    return result;
}
开发者ID:Venom4W,项目名称:ice,代码行数:33,代码来源:StringConverter.cpp

示例3: Initialize

void Enemy::Initialize(b2World& world, b2Vec2 position) {
	bodyDef.position = position;
	bodyDef.type = b2_dynamicBody;
	bodyDef.fixedRotation = true;
	body = world.CreateBody(&bodyDef);

	Convert convert;
	b2Vec2 vs0, vs1, vs2, vs3;

	b2Vec2* vs = new b2Vec2[4];
	vs0 = convert.CoordPixelsToWorld(0, 50, 50.0f, 50.0f);
	vs1 = convert.CoordPixelsToWorld(0, 0, 50.0f, 50.0f);
	vs2 = convert.CoordPixelsToWorld(50, 0, 50.0f, 50.0f);
	vs3 = convert.CoordPixelsToWorld(50, 50, 50.0f, 50.0f);
	vs[0].Set(vs0.x, vs0.y);
	vs[1].Set(vs1.x, vs1.y);
	vs[2].Set(vs2.x, vs2.y);
	vs[3].Set(vs3.x, vs3.y);
	shape.Set(vs, 4);
	delete vs;

	fixtureDef.density = 1.0f;
	fixtureDef.friction = 0.0f;
	fixtureDef.shape = &shape;
	body->CreateFixture(&fixtureDef);

	b2Fixture* enemySensorFixture = body->CreateFixture(&fixtureDef);
	ContactUserData* cud = new ContactUserData();
	cud->type = ContactUserData::Type::ENEMY;
	cud->data = this;
	enemySensorFixture->SetUserData(cud);
}
开发者ID:JGeyer,项目名称:Game-Platform,代码行数:32,代码来源:Enemy.cpp

示例4: getOutputsStrASCII

QString TransitionInfoBin::getOutputsStrASCII()
{
  unsigned char ascii[MAX_CHARARRAY_LENGTH];
  int len;
  Convert conv;

  outputs->convertToASCII(ascii, MAX_CHARARRAY_LENGTH, len, FALSE);
  return conv.asciiToReadableStr(ascii, len);
}
开发者ID:Kampbell,项目名称:qfsm,代码行数:9,代码来源:TransitionInfoBin.cpp

示例5: match

static bool match(UnsafeRawOp* x,
                  Instruction** base,
                  Instruction** index,
                  int*          log2_scale) {
  Instruction* instr_to_unpin = NULL;
  ArithmeticOp* root = x->base()->as_ArithmeticOp();
  if (root == NULL) return false;
  // Limit ourselves to addition for now
  if (root->op() != Bytecodes::_ladd) return false;
  // Try to find shift or scale op
  if (match_index_and_scale(root->y(), index, log2_scale, &instr_to_unpin)) {
    *base = root->x();
  } else if (match_index_and_scale(root->x(), index, log2_scale, &instr_to_unpin)) {
    *base = root->y();
  } else if (root->y()->as_Convert() != NULL) {
    Convert* convert = root->y()->as_Convert();
    if (convert->op() == Bytecodes::_i2l && convert->value()->type() == intType) {
      // pick base and index, setting scale at 1
      *base  = root->x();
      *index = convert->value();
      *log2_scale = 0;
    } else {
      return false;
    }
  } else {
    // doesn't match any expected sequences
    return false;
  }
  // Typically the addition is pinned, as it is the result of an
  // inlined routine. We want to unpin it so as to avoid the long
  // addition, but in order to do so we must still ensure that the
  // operands are pinned, as they may be computed arbitrarily before
  // the Unsafe op completes (even if the Unsafe op is pinned). At
  // this point we do not really need to pin Unsafe raw or object
  // gets.
  if (root->is_pinned()) {
    if (root->pin_state() == Instruction::PinInlineReturnValue) {
      assert(x->is_pinned(), "All unsafe raw ops should be pinned");
      root->unpin(Instruction::PinInlineReturnValue);
      (*base)->pin();
      (*index)->pin();
    } else {
      // can't safely unpin this instruction
      return false;
    }
  }

  if (PrintUnsafeOptimization && instr_to_unpin != NULL) {
    tty->print_cr("pin_state = 0x%x", instr_to_unpin->pin_state());
    instr_to_unpin->print();
  }
  return true;
}
开发者ID:MuniyappanV,项目名称:jdk-source-code,代码行数:53,代码来源:c1_Canonicalizer.cpp

示例6: Regex

//编码问题,如果是gbk,则转成utf8
string Doc::charset_convert()
{
    string pattern = "charset\\s?=\\s?(.*?)\"";
    Regex *regex = new Regex(pattern);
    string charset = regex->match_one(content, 1);
    if (charset == "utf-8" || charset == "utf8") //如果文档是utf8编码,则不做特别处理 
        return content;
    else if (charset == "gbk" || charset == "gb2312") //如果是gbk编码,则转换成utf8编码 
    {
        Convert *con = new Convert("gbk", "utf8");
        return con->exec(content);
    }
    else //其他编码不予以考虑,直接跳过 
        return "";
}
开发者ID:lylemalik,项目名称:triple,代码行数:16,代码来源:doc.cpp

示例7: while

void Information_Hiding::Execute(ifstream &CoverData, ofstream &StegoData){
	Convert convert;
	int in = 0;
	int index = 0;
	int counter = 0;
	char CharOfMessBinary[8] = {'\0'};
	while(CoverData.good())
	{
		bool isChange = false;
		char CharOfImageBinary[8] = {'\0'};
		char c = CoverData.get();
		int ascii = (int)c;
		int _ascii = abs(ascii);
		if(ascii != _ascii)	isChange = true;
		convert.ConvertToBinary(_ascii, CharOfImageBinary);
		if(counter >= 55){
			bool flag = false;
			//-----------------------------------------------------//
			if(index == 0 && in < message.length()-1){
				char encodeChar = message[in];
				int asc = (int)encodeChar;
				convert.ConvertToBinary(asc, CharOfMessBinary);
				flag = true;
			}
			if(in >= message.length() -1 ){
				index = -1;
			}	
			//------------------------------------------------------//
			if(index != -1){
				CharOfImageBinary[7] = CharOfMessBinary[index];
				StegoData << convert.ConvertToChar(CharOfImageBinary,isChange);
			}
			else	StegoData << c;
			if(index != -1){
				index++;
				if(index == 8){
					index = 0;
					in++;
				}
			}
			
		}
		if(counter < 55)
			StegoData << c;
		counter++;
	}
}
开发者ID:VanHop,项目名称:HidenInfoIntoImage,代码行数:47,代码来源:Infomation_Hiding.cpp

示例8: main

int main(int argc, char const* argv[])
{
	google::InitGoogleLogging(argv[0]);
	FLAGS_logtostderr = true;
	ilInit();

	LOG(INFO) << "Using devil library version " << ilGetInteger(IL_VERSION_NUM);

	// Allocate images
	ILuint images[2]; // 0 for read, 1 for write
	ilGenImages(2, images);
	IL_CHECK_ERROR();

	// Read image
	ilBindImage(images[0]);
	ilLoadImage("lena_color.bmp");
	IL_CHECK_ERROR();
	auto bpp = ilGetInteger(IL_IMAGE_BPP); // bpp = byte per pixels
	CHECK_EQ(bpp, 3) << "BPP must be 3";
	auto w = ilGetInteger(IL_IMAGE_WIDTH);
	auto h = ilGetInteger(IL_IMAGE_HEIGHT);
	LOG(INFO) << "Load image width = " << w << ", height = " << h;
	ILubyte *color_img_ptr = ilGetData();
	IL_CHECK_ERROR();

	// Allocate image for store
	ilBindImage(images[1]);
	IL_CHECK_ERROR();
	ilTexImage(w, h, 1, bpp, IL_LUMINANCE, IL_UNSIGNED_BYTE, NULL);
	ILubyte *gray_img_ptr = ilGetData();
	IL_CHECK_ERROR();

	// Convert!
	Convert c;
	c.RGB2Gray(color_img_ptr, gray_img_ptr, w, h);

	// store image
	ilBindImage(images[1]);
	ilEnable(IL_FILE_OVERWRITE);
	ilSaveImage("lena_gray.bmp");
	IL_CHECK_ERROR();

	ilDeleteImages(2, images);
	return 0;
}
开发者ID:JieFangD,项目名称:Orientation,代码行数:45,代码来源:main.cpp

示例9: main

int main (int argc, char* argv[])
{
    if (argc != 4) {
        error("usage: %s number base1 base2", argv[0]);
        return 1;
    }
    std::string str(argv[1]);
    int base1 = std::stoi(std::string(argv[2]));
    int base2 = std::stoi(std::string(argv[3]));
    Convert convert;
    try {
        std::string res;
        res = convert.convert(str, base1, base2);
        std::cout << str << " in base " << base2 << " is " << res << std::endl;
    } catch(const std::invalid_argument& ia) {
        error("%s", ia.what());
        return 1;
    }
    return 0;
}
开发者ID:KudeGit,项目名称:elments_of_programming_interview,代码行数:20,代码来源:es8.cpp

示例10: getCodeStr

/**
 * Returns a string representing the coding of the state
 *
 * @param type If 'Binary' a binary string is returned, otherwise an integer string.
 * @returns The resulting string
 */
QString State::getCodeStr(int type/*=-1*/)
{
  Convert conv;
  QString res;
  int stateCodeSize;
  stateCodeSize=machine->getNumEncodingBits();

  if (type==-1)
    type = machine->getType();

  switch (type)
  {
    case Binary:
      res = conv.intToBinStr(code, stateCodeSize);
      return res;
    default:
      res.setNum(code);
      return res;
  }
}
开发者ID:Kampbell,项目名称:qfsm,代码行数:26,代码来源:State.cpp

示例11: GetPrgRes

void ParserManager::ShowConvertingInfo()
{
HWND conv_tab = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_convert);

	if( conv_type==0 || conv_input_unit==-1 || conv_output_unit==-1 ||
		conv_input_unit == conv_output_unit )
	{
		SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "");
		return;
	}

	Convert * pconv = GetPrgRes()->GetConvert();

	// the first unit to the second

	ttmath::Big<1,1> result;
	result.SetOne();
	std::string buffer1 = "1 ";
	buffer1 += pconv->GetUnitAbbr(country, conv_input_unit);
	buffer1 += " = ";

	if(	pconv->Conversion(conv_input_unit, conv_output_unit, result) )
	{
		SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "overflow" );
		return;
	}

	result.ToString(buffer2, 10, false, 3, -1, true);

	buffer1 += buffer2;
	buffer1 += " "; 
	buffer1 += pconv->GetUnitAbbr(country, conv_output_unit);


	// the second unit to the first

	buffer1 += "   1 ";
	buffer1 += pconv->GetUnitAbbr(country, conv_output_unit);
	buffer1 += " = ";
	
	result.SetOne();
	if(	pconv->Conversion(conv_output_unit, conv_input_unit, result) )
	{
		SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "overflow" );
		return;
	}

	
	result.ToString(buffer2, 10, false, 3, -1, true);

	buffer1 += buffer2;
	buffer1 += " "; 
	buffer1 += pconv->GetUnitAbbr(country, conv_input_unit);
	
	SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, buffer1.c_str() );
}
开发者ID:somyagupta,项目名称:csc444,代码行数:56,代码来源:parsermanager.cpp

示例12: switch

void Canonicalizer::do_StoreField     (StoreField*      x) {
  // If a value is going to be stored into a field or array some of
  // the conversions emitted by javac are unneeded because the fields
  // are packed to their natural size.
  Convert* conv = x->value()->as_Convert();
  if (conv) {
    Value value = NULL;
    BasicType type = x->field()->type()->basic_type();
    switch (conv->op()) {
    case Bytecodes::_i2b: if (type == T_BYTE)  value = conv->value(); break;
    case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
    case Bytecodes::_i2c: if (type == T_CHAR  || type == T_BYTE)  value = conv->value(); break;
    }
    // limit this optimization to current block
    if (value != NULL && in_current_block(conv)) {
      set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(),
                                   x->state_before(), x->needs_patching()));
      return;
    }
  }

}
开发者ID:lizhekang,项目名称:TCJDK,代码行数:22,代码来源:c1_Canonicalizer.cpp

示例13: main

int main() 
{
  int number, base, answer;
  
  //RECEIVE INPUT
  cout << "Please enter an integer: ";
  cin >> number;
  
  cout << "Please enter the base of that integer: ";
  cin >> base;
  
  //CALL CONVERT
  Convert c; //create convert obj
  answer = c.convertToDec(number, base);
  
  //GIVE ANSWER
  if (answer != -1)
  	cout << "The given integer in decimal format is: " << answer << "." << endl;
  else 
  	cout << "The given integer " << number << " with base " << base << " is invalid." << endl;
  
  return 0;
}
开发者ID:mmnavarr,项目名称:OOPCPP,代码行数:23,代码来源:main.cpp

示例14: next

/**
 * Proceeds with the next step in the simulation.
 * Reads the inputs from the inputs field and sends them to the machine.
 */
void Simulator::next()
{
  QString in, out;
  int numin, numout;
  GState* next_state;
  Convert conv;
  IOInfo* ioinfo;
  IOInfoBin iobin(IO_MealyIn);
  IOInfoASCII ioascii(IO_MealyIn);
  Error err;

  numin = machine->getNumInputs();
  numout = machine->getNumOutputs();

  in = simdlg->getInputs();
//  bin = new char[numin+1];
  if (simdlg->isIBinChecked())
  {
    
    if (Transition::conditionValid(Binary, in, FALSE))
    {
      if (!simdlg->isClockOn())
        err.info(tr("Input is not in binary format."));
      else
        //simdlg->setInputs("");
	simdlg->clearInput();
      return;
    }
    iobin = conv.binStrToX10(numin, in, IO_MealyIn);
    ioinfo = &iobin;
  }
  else if (simdlg->isIHexChecked())
  {
    QString intmp=in;
    intmp = intmp.replace(QRegExp("[0-9a-fA-F\\s]"), "");
    if (!intmp.isEmpty())
    {
      if (!simdlg->isClockOn())
        err.info(tr("Input is not in hexadecimal format."));
      else
        //simdlg->setInputs("");
	simdlg->clearInput();
      return;
    }
    iobin = conv.hexStrToX10(numin, in, IO_MealyIn);
    ioinfo = &iobin;
  }
  else  // ASCII
  {
    ioascii.setInfo(in); 
    ioinfo = &ioascii;
    if (!ioascii.isSingle())
    {
      if (!ioascii.getInfo().isEmpty() && !simdlg->isClockOn())
        err.info(tr("The input is not a single character.")); //
      else
        //simdlg->setInputs("");
	simdlg->clearInput();
      return;
    }
  }

//  IOInfoBin ioinfo(bin, numin);

  next_state = next(ioinfo, out);

  if (next_state)
  {
    simdlg->setOutputs(out);
    setCurrentState(next_state);
    main->repaintViewport();

  }
  if (simdlg->isClockOn() && simdlg->isIASCIIChecked())
  {
    simdlg->resetBits();
    simdlg->clearInput();
  }
  else
    simdlg->selectFirst();
//  delete [] bin;
}
开发者ID:Kampbell,项目名称:qfsm,代码行数:86,代码来源:Simulator.cpp

示例15: if

// Here we set all the flags
void ScanBlocks::scan_block(BlockBegin* block, ScanResult* desc, bool live_only) {
  for (Instruction* n = block; n != NULL; n = n->next()) {
    if (live_only && !n->is_pinned() && (n->use_count() ==  0)) {
      // don't look at unused instructions because no code is emitted for them
      continue;
    }

    ValueTag tag = n->type()->tag();
    if (tag == floatTag) desc->set_has_floats(true);
    else if (tag == doubleTag) desc->set_has_doubles(true);
    if (n->as_StateSplit() != NULL) {
      if (n->as_Invoke() != NULL) {
        desc->set_has_calls(true);
      } else if (n->as_NewArray() || n->as_NewInstance() || n->as_AccessMonitor()) {
        desc->set_has_slow_cases(true);
      }  else if(n->as_Intrinsic() != NULL) {
        Intrinsic* i = n->as_Intrinsic();
        if (i->id() == methodOopDesc::_arraycopy) desc->set_has_slow_cases(true);
        if (!i->preserves_state()) desc->set_has_calls(true);
      }
    } else if (n->as_AccessField() != NULL) {
      AccessField* af = n->as_AccessField();
      if (!af->is_initialized() || !af->is_loaded()) desc->set_has_class_init(true);
    } else if (n->as_AccessLocal() != NULL) {
      AccessLocal* local = n->as_AccessLocal();
      StoreLocal* store = n->as_StoreLocal();
      int use_count = 0;
      if (store != NULL) {
        if (!store->is_eliminated()) {
          use_count = 1;
        }
      } else {
        use_count = n->use_count();
      }
      if (use_count > 0) {
        ValueType* type = local->type();
        assert(local->has_offset(), "must have had offset allocated");
        accumulate_access(in_words(local->offset()), tag, use_count);
      }
    }
#ifdef SPARC
    else {
      if (n->as_Convert() != NULL) {
        Convert* conv = n->as_Convert();
        switch (conv->op()) {
          case Bytecodes::_l2f: 
          case Bytecodes::_l2d: 
          case Bytecodes::_f2l: 
          case Bytecodes::_d2l: 
          case Bytecodes::_d2i: { desc->set_has_calls(true); break; }
        }
      } else if (n->as_ArithmeticOp() != NULL) {
        ArithmeticOp* arith = n->as_ArithmeticOp();
        switch (arith->op()) {
          case Bytecodes::_lrem:  
          case Bytecodes::_ldiv:  
          case Bytecodes::_lmul: 
          case Bytecodes::_drem: 
          case Bytecodes::_frem: { desc->set_has_calls(true); break; }
        }
      }
    }
#endif
  }
}
开发者ID:fatman2021,项目名称:myforthprocessor,代码行数:66,代码来源:c1_ScanBlocks.cpp


注:本文中的Convert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。