无符号字符的键盘输入?

时间:2015-12-22 12:31:35

标签: c++ visual-c++ unsigned-char

uchar szPlaintext[128];                        //dato da criptare 
cout << "\nInserisci testo : ";
getline(cin, szPlaintext);

我用getline尝试了它(cin,szPlaintext);但是我有很多错误。我用VS2015编译。 我试图在我的程序中实现AES(不是我的); uchar声明是这样的。

uchar szPlaintext [128] = "text that I want to insert";

错误是:

1>d:\download\scuola\c++\virtualaes\virtualaes\encrypt.cpp(32): error C2672: 'getline': no matching overloaded function found
1>d:\download\scuola\c++\virtualaes\virtualaes\encrypt.cpp(32): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)': could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'uchar [128]'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\string(157): note: see declaration of 'std::getline'
1>d:\download\scuola\c++\virtualaes\virtualaes\encrypt.cpp(32): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)': expects 3 arguments - 2 provided
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\string(146): note: see declaration of 'std::getline'
1>d:\download\scuola\c++\virtualaes\virtualaes\encrypt.cpp(32): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &)': could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'uchar [128]'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\string(126): note: see declaration of 'std::getline'
1>d:\download\scuola\c++\virtualaes\virtualaes\encrypt.cpp(32): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)': expects 3 arguments - 2 provided
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\string(73): note: see declaration of 'std::getline'
Pietrob0b
Utente Junior

Messaggi: 36
Iscritto il: 10 dic 2015, 20:44

2 个答案:

答案 0 :(得分:0)

std::getline采用- (void) queryData { imageCollectionCell *cell = (imageCollectionCell *)[self.myCollectionView cellForItemAtIndexPath:[[self.myCollectionView indexPathsForSelectedItems] firstObject]]; cell.imageViewCell.image = nil; NSLog(@"initiated"); [self.refreshControl endRefreshing]; PFObject *queryPhotos = self.userInformationObject; PFQuery *query = [PFQuery queryWithClassName:@"Photo"]; [query whereKey:@"userTookPhoto" equalTo:queryPhotos]; [query orderByAscending:@"createdAt"]; [query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) { if (!error) { NSLog(@"Query no error"); imageFilesArray = [[NSArray alloc] initWithArray:objects]; } }]; [self.myCollectionView reloadData]; } 引用,而不是原始指针。

std::string

答案 1 :(得分:-1)

正如其他人已经指出的那样,std :: getline引用了std :: string not&#34; char *&#34; ,所以你的程序编译失败。 以下是std :: getline的两个版本。

istream& getline (istream& is, string& str, char delim);

istream& getline (istream& is, string& str);

现在,假设您想要char中的输入字符串,如何使其工作。请遵循以下程序。

// Example program
#include <iostream>
#include <string>
#include<cstring>

int main()
{
    char szPlaintext[128];                        //dato da criptare 
    std::cout << "\nInserisci testo : ";
    std::string str ;
    getline(std::cin, str);
    strcpy(szPlaintext,str.c_str());

    std::cout << szPlaintext;
}