1. string형에서 바꾸고자 할 때

#include <algorithm>
#include <cctype>
// 위의 2개의 라이브러리 추가

string s;

> lowercase all characters
transform (s.begin(), s.end(),  s.begin(), tolower);                 
   
> uppercase all characters
transform (s.begin(), s.end(), s.begin(), toupper);    

[출처] http://blog.naver.com/PostView.nhn?blogId=young4862&logNo=100088120933&redirect=Dlog&widgetTypeCall=true



2. char형에서 바꾸고자 할 때

#include <string>
// string 라이브러리가 있어야 사용 가능

char c[20];

> lowercase all characters
strlwr(c);

> uppercase all characters
strupr(c);

[출처] http://blog.naver.com/PostView.nhnblogId=young4862&logNo=100088120933&redirect=Dlog&widgetTypeCall=true


'프로그래밍 > C/C++' 카테고리의 다른 글

반올림 함수  (0) 2012.03.28
Single char to int  (0) 2012.03.15
getline(cin, temp);  (0) 2011.09.26
Visual Studio 2010에서 콘솔 창이 바로 꺼질 때  (0) 2011.06.22
C++ string tokenizer  (0) 2011.05.27
Posted by halloRa
,

자꾸 헷갈려서 짜증나서 정리.

cin.getline()이 있고
getline()이 있다.


1. cin.getline();
char temp[size];
cin.getline(temp, 256);


2. getline();
string temp;
getline(cin, temp);

더 자세한건 찾아보도록!


'프로그래밍 > C/C++' 카테고리의 다른 글

Single char to int  (0) 2012.03.15
C++에서 소문자, 대문자 바꾸기  (0) 2011.10.11
Visual Studio 2010에서 콘솔 창이 바로 꺼질 때  (0) 2011.06.22
C++ string tokenizer  (0) 2011.05.27
String to Integer & Integer to String  (0) 2011.05.27
Posted by halloRa
,

저번에 블로그에 vs2010에서 콘솔 창이 바로 꺼질 때
시스템 환경 부분을 고쳐서 콘솔 창이 바로 꺼지지 않도록 만들었는데

이번에 새로운 방식을 알게 되었다.

system("pause");

와 같은 명령어를 프로그램 제일 마지막에 넣어주면
시스템 환경을 고쳤을 때와 같이
"계속하시려면 어쩌구저쩌구"와 같은 문구를 볼 수 있게 된다.

'프로그래밍 > C/C++' 카테고리의 다른 글

C++에서 소문자, 대문자 바꾸기  (0) 2011.10.11
getline(cin, temp);  (0) 2011.09.26
C++ string tokenizer  (0) 2011.05.27
String to Integer & Integer to String  (0) 2011.05.27
Visual Studio 2010 에서 실행창이 바로 꺼질 때  (0) 2011.05.27
Posted by halloRa
,

// string tokenizer
void Tokenize(const string& str, vector<string>& tokens, const string& delimiters = ",")
{
 // 맨 첫 글자가 구분자인 경우 무시
 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
 // 구분자가 아닌 첫 글자를 찾는다
 string::size_type pos     = str.find_first_of(delimiters, lastPos);

 while (string::npos != pos || string::npos != lastPos)
 {
  // token을 찾았으니 vector에 추가한다
  tokens.push_back(str.substr(lastPos, pos - lastPos));
  // 구분자를 뛰어넘는다.  "not_of"에 주의하라
  lastPos = str.find_first_not_of(delimiters, pos);
  // 다음 구분자가 아닌 글자를 찾는다
  pos = str.find_first_of(delimiters, lastPos);
 }
}

Posted by halloRa
,

> String to Integer
atoi()
ex)
string number="2";
atoi(number.c_str());

> Integer to String
itoa()
주의할 점은 이 함수는 표준이 아니다. 특정 몇 몇 컴파일러에서만 작동 가능.
ex)
char buffer[10];
int number=2;
itoa(number, buffer, 10); <- 10은 10개를 의미하는 것이 아니라 10진수를 의미. 즉, 2로 쓰면 binary, 16으로 쓰면 16진수로 표현

[새로운 방법]
stringstream tmpStr;
tmpStr << number;
cout << tmpStr.str() << endl;


Posted by halloRa
,

Visual Studio 2010에서
열심히 프로그램 작성 후 실행할 때
실행 창이 결과를 확인도 하기 전에 꺼지는 경우가 발생할 경우

프로젝트 > 속성 > 링커 > 시스템 > 하위 시스템

으로 가서 값을 콘솔로 바꿔주자!

'프로그래밍 > C/C++' 카테고리의 다른 글

C++에서 소문자, 대문자 바꾸기  (0) 2011.10.11
getline(cin, temp);  (0) 2011.09.26
Visual Studio 2010에서 콘솔 창이 바로 꺼질 때  (0) 2011.06.22
C++ string tokenizer  (0) 2011.05.27
String to Integer & Integer to String  (0) 2011.05.27
Posted by halloRa
,