Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何初始化结构大小/长度_C++ - Fatal编程技术网

C++ 如何初始化结构大小/长度

C++ 如何初始化结构大小/长度,c++,C++,我必须创建一个结构并在循环中运行它,这不是问题,但它必须在用户选择如何运行时运行特定次数 例: 如果我想运行十次,我可以使用 for (int x=0, x<10, x++) .... for(intx=0,x让我们假设变量n将保留用户输入的值 int n; 然后循环将看起来像 for ( int x = 0; x < n; x++ ) { // some code } 要检查名称是否只包含字母,可以应用算法std::all_of和标准C函数isalpha 比如说 #i

我必须创建一个结构并在循环中运行它,这不是问题,但它必须在用户选择如何运行时运行特定次数

例:

如果我想运行十次,我可以使用

for (int x=0, x<10, x++)
....

for(intx=0,x让我们假设变量n将保留用户输入的值

int n;
然后循环将看起来像

for ( int x = 0; x < n; x++ )
{
    // some code
}
要检查名称是否只包含字母,可以应用算法
std::all_of
和标准C函数
isalpha

比如说

#include <algorithm>
#include <cctype>

//...

std::string name;

std::getline( std::cin, name );

if ( !name.empty() && std::all_of( name.begin(), name.end(), 
                                   []( char c ) { return std::isalpha( c ); } ) )
{
    std::cout << name << " is valid name" << std::endl;
}!
#包括
#包括
//...
std::字符串名;
std::getline(std::cin,name);
如果(!name.empty()&&std::all_of(name.begin(),name.end(),
[](字符c){return std::isalpha(c);})
{
标准::cout
std::cin >> n;
#include <algorithm>
#include <cctype>

//...

std::string name;

std::getline( std::cin, name );

if ( !name.empty() && std::all_of( name.begin(), name.end(), 
                                   []( char c ) { return std::isalpha( c ); } ) )
{
    std::cout << name << " is valid name" << std::endl;
}!