- statc_cast<int>
- const
cout 기본 입출력
http://young_0620.blog.me/50189720699
- setw(x)
- fixed
- setprecision(x)
- showpoint
- left, right
// This program illustrates the use of the left and right manipulators.
#include <iostream>
#include <iomanip> // Needed to use stream manipulators
#include <string>
using namespace std;
int main()
{
string month1 = "January",
month2 = "February",
month3 = "March";
int days1 = 31,
days2 = 28,
days3 = 31;
double high1 = 22.6,
high2 = 37.4,
high3 = 53.9;
cout << fixed << showpoint << setprecision(1);
cout << "Month Days High\n";
cout << left << setw(12) << month1
<< right << setw(4) << days1 << setw(9) << high1 << endl;
cout << left << setw(12) << month2
<< right << setw(4) << days2 << setw(9) << high2 << endl;
cout << left << setw(12) << month3
<< right << setw(4) << days3 << setw(9) << high3 << endl;
return 0;
}
#include <iomanip>
cout.setf(ios :: fixed);
cout.setf(ios :: showpoint);
cout.precision(3);
세개는 붙어다니는 하나의 세트라고 봐도 좋을 것 같다.
cout.setf(ios :: fixed); 가 뜻하는 것은 고정 소수점 출력,
cout.setf(ios :: showpoint); 는 소수점을 보여준다는 것,
cout.precision(3);는 소수점 이하 3자리를 뜻한다.
cin
- getline(cin, string)
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
string city;
cout << "Please enter your name: ";
getline(cin, name);
cout << "Enter the city you live in: ";
getline(cin, city);
cout << "Hello, " << name << endl;
cout << "You live in " << city << endl;
return 0;
}
- cin.get(x)
String
- strcpy(x,y)
#include <cmath>
- sqrt()
#include <cstdlib>
- rand()
- srand()
#include <fstream>
[파일 쓰기]
#include <iostream>
#include <fstream> // Needed to use files
using namespace std;
int main()
{
ofstream outputFile;
outputFile.open("demofile.txt");
cout << "Now writing information to the file.\n";
// Write 3 great names to the file
outputFile << "Bach\n";
outputFile << "Beethoven\n";
outputFile << "Mozart\n";
// Close the file
outputFile.close();
cout << "Done.\n";
return 0;
}
[파일 읽기]
// This program uses the >> operator to read information from a file.
#include <iostream>
#include <fstream> // Needed to use files
#include <string>
using namespace std;
int main()
{
ifstream inFile;
string name;
inFile.open("demofile.txt");
cout << "Reading information from the file.\n\n";
inFile >> name; // Read name 1 from the file
cout << name << endl; // Display name 1
inFile >> name; // Read name 2 from the file
cout << name << endl; // Display name 2
inFile >> name; // Read name 3 from the file
cout << name << endl; // Display name 3
inFile.close(); // Close the file
cout << "\nDone.\n";
return 0;
}
'Programming Language > C++' 카테고리의 다른 글
[계절학기 C++] Class (0) | 2014.07.09 |
---|---|
[계절학기 C++] Array (0) | 2014.07.09 |
[강좌2] 3일차 (0) | 2014.06.27 |
vector... (0) | 2013.07.10 |
c++ 동기화객체 (0) | 2013.07.08 |