2012-03-07 20 views
0

標準では文字列の値を使用するプログラムがあります。 ユーザーが値を入力できるように変更するにはどうすればよいですか?文字列のユーザー入力

よろしく

Joriek

#include <iostream> 
#include <string> 

using namespace std; 

int main() 
{ 

std::string id_strnormal = "4a"; 
std::string code = "10 4a 00 11 22 33 44 55 66 77 88 99 10 03"; 

std::string start_str = code.substr(0, 2); 
std::string id_str = code.substr(3, 2); 

int str_length = code.length(); 
std::string stop_str = code.substr(str_length-5); 


if (id_str == id_strnormal) 
{ 
      std::cout << code << std::endl; 
} 
if (id_str != id_strnormal) 
{ 
    std::cout << "package id isn't 4a" << std::endl; 
} 
system ("pause"); 
return 0; 
} 
+0

あなたのコードで 'using namespace std;'を追加する目的を打ち破っていませんか? ^^ –

+0

あなたは基本的なC++の本を読んだり、読んだり読んだりすることができます。これは非常に基本的な質問です –

答えて

0

は、標準入力を処理するためのstd::cinを見てみましょう。

std::cin>>id_strnormal; //instead of id_strnormal = "4a"; 
0

。ユーザーの入力が4aになると、std :: cinは動作しませんが、上記の例が有効になります。

1

あなたが使用することができます:getlineの(CIN、文字列)ユーザーの入力をcin>>input などを使用することにより

+0

ありがとう – Joriek

関連する問題