前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/*★ STL string のプログラム 前田 稔 ★*/
#include <iostream>
#include <string>
using namespace std;
int main()
{ string s;
s= "12345";
cout << "1番目の文字列: " << s << endl;
s= "abcdefg";
cout << "2番目の文字列: " << s << endl;
s= "ABCDEFGHIJKLMN";
cout << "3番目の文字列: " << s << endl;
return 0;
}
|
std::string str[15] =
{ "g cube",
"v - 5 - 5 - 5",
"v 5 - 5 - 5",
"v - 5 5 - 5",
"v 5 5 - 5",
"v - 5 - 5 5",
"v 5 - 5 5",
"v - 5 5 5",
"v 5 5 5",
"f 1 3 4 2",
"f 1 5 7 3",
"f 2 4 8 6",
"f 1 2 6 5",
"f 3 7 8 4",
"f 5 6 8 7" };
|
![]()
// STL string で Debug() 関数を定義 Maeda Minoru
#include <iostream>
#include <string>
#include <windows.h> //OutputDebugString
#include <strsafe.h> //StringCbPrintf
using namespace std;
void Debug(string msg, int v)
{ char work[80];
if (StringCbPrintf(work, 80, "%s(%d)\r\n", msg.data(), v) != 0)
MessageBox(NULL,"CbPrintf Error","Error",MB_OK);
OutputDebugString(work);
}
|
s= "12345";
cout << "1番目の文字列: " << s << endl;
Debug(s, s.length());
s= "abcdefg";
cout << "2番目の文字列: " << s << endl;
Debug(s, s.length());
s= "ABCDEFGHIJKLMN";
cout << "3番目の文字列: " << s << endl;
Debug(s, s.length());
|
![]()
#include <windows.h> // OutputDebugString
#include <string> // STL の String を使う
// ',/' で区切られた文字列を数値に変換して vector でリターン
std::vector<int> MySplit::split(Platform::String^ str)
{
std::vector<int> vt;
std::wstring s;
std::wstring Word;
int Size, Col, wk;
s = str->Data();
s += L"/";
OutputDebugString(s.data());
Size = s.length() - 1;
vt.clear();
for (Col = 0; Col < Size;)
{
wk = s.find_first_not_of(L" ,/", Col);
Col = wk;
wk = s.find_first_of(L" ,/", Col);
if (wk==Col) break;
Word = Word.assign(s, Col, wk - Col);
vt.push_back(_wtoi(Word.data()));
Col = wk + 1;
}
return vt;
}
|
// STL wstring のプログラム Maeda Minoru
#include <windows.h>
#include <string>
#include <strsafe.h> //StringCchPrintf()
#include <conio.h> //_getch()
using namespace std;
void Debug(wstring msg, int v)
{ WCHAR work[80];
char wk[80];
if (StringCchPrintf(work, 80, L"%s(%d)\r\n", msg.data(), v) != 0)
MessageBox(NULL,L"CchPrintf Error",L"Error",MB_OK);
OutputDebugString(work);
WideCharToMultiByte(CP_ACP,0,work,-1,wk,80,NULL,NULL);
printf(wk);
}
int main()
{ wstring s;
s= L"12345";
Debug(s, s.length());
s= L"abcdefg";
Debug(s, s.length());
s= L"ABCDEFGHIJKLMN";
Debug(s, s.length());
_getch();
return 0;
}
|
![]()