C++----练习--string输入输出

1、要使用标准库中的string 类型、也要增加头文件

#include<string>

2、例子:

#include<iostream>
#include<string>
using std::string; // 注意using 后面是要接 ";" 号的。
using std::cin;
using std::cout;
using std::endl;

int main()
{
    string string_var;
    cin>>string_var;
    cout<<string_var<<endl;
    return 0;

}
时间: 2024-08-10 17:06:00

C++----练习--string输入输出的相关文章

? 洛谷 P3056 [USACO12NOV]笨牛Clumsy Cows

P3056 [USACO12NOV]笨牛Clumsy Cows 题目描述 Bessie the cow is trying to type a balanced string of parentheses into her new laptop, but she is sufficiently clumsy (due to her large hooves) that she keeps mis-typing characters. Please help her by computing th

tchar 输入输出类 和 string 类 函数简单说明 总结各种前缀后缀

标准输入输出printf类_tprintf : 类同printf_tprintf_l : 类同printf, 但是"_l"表示第二个参数是一个locale.locale是操作系统对语言设定的参数, 这个会影响ANSI字符的语言识别, 在Unicode下应该是无差别的_tprintf_s : 类图printf, 但是和_tprintf相比, _tprintf_s多会做一些检查工作.如果你的"format string"是动态的, 这个能帮助你._tprintf_s_l

c++ 中string用c输入输出

对于string自带的函数 c_str()返回的const char*类型,对于scanf函数不能使用,可以通过如下方法使用 string s; scanf("%s",&*s.begin())   => s.begin() 返回的是一个const char* 常量指针,通过*对其取类容,再通过&地址符得到字符指针. 对于string类型的输出 string s; printf("%s\n",s.c_str()); cout << s

ZOJ3784 String of Infinity 高大上的AC自动机 数据原来这么水啊!不算输入输出只有5-7行

找给定s集合里面word全部是同一个字符的,这样的word有几个,如果数量<m就yes,否则就no.#include<iostream> #include<cstring> #include<string> #include<algorithm> using namespace std; int main(void) { int t; string a; cin>>t; while(t--) { int n,m; cin>>n&

蓝鸥Unity开发基础——控制台输入输出学习笔记

控制台输入输出:本节内容控制台输入输出.格式化输出 using System; namespace Lesson09{    class MainClass    {        public static void Main (string[] args)        {            /* 控制台输出语句             * 1.Console.WriteLine("");             * 2.Console.Write (" "

黑马程序员---C基础9【字符串的输入输出】【字符串相关函数】【指针】【指针变量初始】【二级指针】

------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- [字符串的输入输出] 1.字符串输出: %s-------从给定的地址开始输出字符直到遇到\0停止: printf("%s\n",&a[3]);  printf("%s\n",a); char a[]="hellowo\0rd!"; 2.字符串输入: 从键盘上接收一个字符串,保存在以a为首地址的字符数组中 scanf("%s&

C++中字符数组和字符串string

字符数组 C++中字符数组用char str[]可以用来表示一个字符串. (1)   数组的大小和字符串的长度. 数组的大小一定要大于字符串的长度,因为系统会自动补上一个'\0'作为字符串的结束标志.当然对于未初始化的也补'\0'. #include <iostream> #include <string> using namespace std; int main() { char str[11] = "I am happy"; // 系统会自动补上'\0'空

c/c++日期时间处理与字符串string转换

在c/c++实际问题的编程中,我们经常会用到日期与时间的格式,在算法运行中,通常将时间转化为int来进行计算,而处理输入输出的时候,日期时间的格式却是五花八门,以各种标点空格相连或者不加标点. 首先,在c中,是有一个标准的日期时间结构体的,在标准库wchar.h内,我们可以看到结构体tm的声明如下: 1 #ifndef _TM_DEFINED 2 struct tm { 3 int tm_sec; /* seconds after the minute - [0,59] */ 4 int tm_

C/C++ string和char数组对比

string是c++特有的,使用时需添加头文件#include<string> (一)#include<string.h>和#include<cstring>以及#include<string.h>区别 <string.h> <string.h>是C版本的头文件,包含比如strcpy.strcat之类的字符串处理函数. <cstring> 在C++标准化(1998年)过程中,为了兼容以前,标准化组织将所有这些文件都进行了新