在C ++中哪里使用空字符常量''?

时间:2018-12-20 13:41:03

标签: c++

在C ++中,不能输出空字符常量''或将其分配给字符。编译器会说“错误:期望的表达式”。我们可以将其放在C ++源代码中吗?如果没有,“”的用法是什么? (空字符常量“是一个',后跟另一个”)

3 个答案:

答案 0 :(得分:12)

  

我们可以将其放入C ++源代码吗?

否,这是语法错误。

  

如果不是,“”的用法是什么?

没有用处,除非您的目的是引起编译错误(对此可能有更好的替代方法,例如override def run(args: List[String]): IO[Nothing, Main.ExitStatus] = for { valueFromDb <- lazyIO(longRunningDbAction) _ <- maybeUseTheValue(valueFromDb) _ <- maybeNeedItAgain(valueFromDb) } yield ExitStatus.ExitNow(0) )。

  

可以理解空字符常量''只是一个纯语法错误,就像一个名为2018ch的变量一样吗?

是的。语法说:

getting it
Calling the database now
The database said 42
getting it
Okay, we need it again here: 42

请注意,与foreach不同,[string]$modules="" foreach ($module in $xmlFile.project.modules) { Write-Output $module.'#comment' } 不是可选的。

旁注:是的,它是一个字符序列-存在多个字符文字。但是除了知道您可能不需要它们之外,您不需要了解它们。只是不要假设它们是字符串。

答案 1 :(得分:3)

好吧,我认为混淆来自字符串可以是空字符串的事实,例如"",所以也许您画了一个平行线,并期望其中有一个像''这样的空字符。

请记住字符串是什么:一系列字符(0、1或更多)(以字符串字符'\0'的结尾终止)。因此""是一个0字符的字符串(尽管存在,但不计字符串的结尾),也就是“空字符串”。

一个角色很好...只是那个一个角色。不是零,不是2或3。字符始终具有一个值。因此,空字符''不存在并且没有意义。

答案 2 :(得分:2)

encoding-prefix毫无意义,因此无法编译,它应该具有什么价值?

请记住,在某个时刻,它们只是内存中的所有位和字节,所以这些字节应具有什么值来表示c-char-sequence

select A.id, A.other_id A.data, A.data2, 
       sum(case when b.data < a.data then 1 else 0 end),
       sum(case when b.other_id = a.other_idid and b.data < a.data then 1 else 0 end),
       sum(case when b.data < a.data and b.sth is true then 1 else 0 end)
from a left join
     b
     on a.id = b.id
group by A.id, A.other_id A.data, A.data2

这些代表“空”字符,这是您最接近## added a script in the process just for test import datetime import sys import pandas as pd cleanup_consent_column = "rwJIedeRwS" omc_master_header = [u'PPAC District Code', u'State Name', u'District Name', u'Distributor Code', u'OMC Name', u'Distributor Contact No', u'Distributor Name', u'Distributor Address', u'SO Name', u'SO Contact', u'SALES AREA CODE', u'Email', u'DNO Name', u'DNO Contact', u'Lat_Mixed', u'Long_Mixed'] #OMC_DISTRIBUTOR_MASTER = "/mnt/data/NFS/TeamData/Multiple/external/mopng/5Feb18_master_ujjwala_latlong_dist_dno_so_v7.csv" #PPAC_MASTER = "/mnt/data/NFS/TeamData/Multiple/external/mopng/ppac_master_v3_mmi_enriched_with_sanity_check.csv" def clean(input_filepath, OMC_DISTRIBUTOR_MASTER, PPAC_MASTER, output_filepath): print("Taylor Swift's clean.") df = pd.read_csv(input_filepath, encoding='utf-8', dtype=object) print ('length of input - {0} - num cols - {1}'.format(len(df), len(df.columns.tolist()))) ## cleanup consent column for x in df.columns.tolist(): if x.startswith("rwJIedeRwS"): del df[x] break ## strip ppac code from the baseline df['consumer_id_name_ppac_code'] = df['consumer_id_name_ppac_code'].str.strip() ## merge with entity to get entity_ids omc_distributor_master = pd.read_csv(OMC_DISTRIBUTOR_MASTER, dtype=object, usecols=omc_master_header) omc_distributor_master = omc_distributor_master.add_prefix("omc_dist_master_") df = pd.merge( df, omc_distributor_master, how='left', left_on=['consumer_id_name_distributor_code', 'consumer_id_name_omc_name'], right_on=['omc_dist_master_Distributor Code', 'omc_dist_master_OMC Name'] ) ## log if anything not found print ('responses without distributor enrichment - {0}'.format(len(df[df['omc_dist_master_Distributor Code'].isnull()]))) print ('num distributors without enrichment - {0}'.format( len(pd.unique(df[df['omc_dist_master_Distributor Code'].isnull()]['consumer_id_name_distributor_code'])) )) ## converting date column df['consumer_id_name_sv_date'] = pd.to_datetime(df['consumer_id_name_sv_date'], format="%d/%m/%Y") df['consumer_id_name_sv_date'] = df['consumer_id_name_sv_date'].dt.strftime("%Y-%m-%d") ## add eventual_ppac_code print ("generating eventual ppac code column") count_de_rows = 0 start_time = datetime.datetime.now() for i, row in df.iterrows(): count_de_rows += 1 if count_de_rows % 10000 == 0: print(count_de_rows) ## if not found in master - use baseline data else go with omc master if row['omc_dist_master_PPAC District Code'] != row['omc_dist_master_PPAC District Code']: df.ix[i, 'eventual_ppac_code'] = row['consumer_id_name_ppac_code'] else: df.ix[i, 'eventual_ppac_code'] = row['omc_dist_master_PPAC District Code'] print(datetime.datetime.now() - start_time) print("I guess it's all alright!") if __name__ == '__main__': print("The main function has been called!") clean(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) 的字符。