当前位置:编程学习 > C/C++ >>

C++ Primer学习笔记 - 第三章

使用using 声明

[cpp]
#include <iostream> 
#include <string> 
 
using std::cin; 
using std::cout; 
using std::endl; 
using std::string; 
 
int main() 

    string code = "This is Test Code"; 
    cout << code 
        << endl; 
 
    system("pause"); 
    return 0; 

结果如下:

 


getline 函数

[cpp] 
#include <iostream> 
#include <string> 
 
using std::cin; 
using std::cout; 
using std::endl; 
using std::string; 
 
int main() 

    string code; 
    while(getline(cin, code)){ 
        cout << code << endl; 
    } 
 
    system("pause"); 
    return 0; 

标准库的 string 类型的成员方法, size() 的返回值,竟然不是 int 类型,而是,神奇的 string::size_type 类型。擦。。。不管是啥玩意儿,总之,不能赋值给 int 变量!

补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,