正如标题所说
有没有办法获得c++中的系统架构?
谢谢!
我有两个 double 类型的向量,我想将它们组合起来形成一个复向量。
vector<double> vReal;
vector<double> vImag;
Run Code Online (Sandbox Code Playgroud)
我如何将以上两者结合起来得到
vector<complex<double>> vComp;
Run Code Online (Sandbox Code Playgroud)
有人可以帮我怎么做吗?
非常感谢。
此致
金丹
我在 C++ 中从其他调用默认构造函数时遇到问题。在Java中是这样的:
class Book {
static private int i;
private String s;
public Book() {
i++;
}
public Book(String s) {
this();
this.s = s;
}
}
Run Code Online (Sandbox Code Playgroud) 我创建了这个链表类来在我的工作中使用它,但我遇到了这个异常“game.exe 中 0x003216D2 处的第一次机会异常:0xC0000005:访问冲突写入位置 0x00000004”。它来自擦除功能,有人可以告诉我如何修复它并解释问题所在
#ifndef LINKEDLIST_HPP
#define LINKEDLIST_HPP
#include <vector>
#include <cassert>
template<typename T>
class Linkedlist
{
private:
// The basic doubly linked Linkedlist node.
// Nested inside of Linkedlist, can be public
// because the Node is itself private
struct Node
{
T _data;
Node *_prev;
Node *_next;
Node( const T & d = T(), Node * p = NULL, Node * n = NULL )
: _data( d ), _prev( p ), _next( n ) { } …Run Code Online (Sandbox Code Playgroud) 我是 C++ 的初学者。我仍然对 makefile 中的标志感到困惑。
-c. -o. -Wall. -g. -std=c++0x.
Run Code Online (Sandbox Code Playgroud)
谁能告诉我所有这些常见标志的作用是什么?
我正在做我的 C++ 作业。我在字符串比较方面遇到问题。
我使用 == 操作比较两个明显相同的字符串,但条件返回 false。调试器还显示两个字符串(存储在不同的变量中)是相同的。我肯定错过了什么。
这是我的代码:
void classCounter() {
ifstream fread;
string linetxt;
char *records[50];
char myLine[100];
char delims[] = "|";
int btotal=0,etotal=0,total=0;
fread.open("F:\\myfile.txt");
while(!fread.eof()) {
getline(fread,linetxt,'\n');
int i = 0;
strcpy(myLine, linetxt.c_str());
records[i] = strtok( myLine, delims );
while( records[i] != NULL )
{
cout << records[i] << "|";
char *bu = "Business";
if(records[i] == bu) {
btotal++;
}
if(records[i] == "Economy") {
etotal++;
}
//printf("%d '%s'\n", i, records[i]);
records[++i] = strtok( NULL, delims );
break;
} …Run Code Online (Sandbox Code Playgroud) 这是这个看似无辜的几行代码。
#include <iostream>
#include <string>
#include <unordered_map>
struct Tag
{
using name_t = std::string;
using tag_map_t = std::unordered_map<name_t, Tag>;
name_t name;
tag_map_t children = {};
};
int main(void)
{
auto foo = Tag{"foo"};
auto bar = Tag{"bar"};
foo.children["bar"] = bar;
std::cout << foo.name << " -> " << foo.children["bar"].name << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
? clang++ --version
clang version 11.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\bin
? clang++ -std=c++14 -Weverything -Werror -Wno-c++98-compat tag.cpp -o tag.exe && …Run Code Online (Sandbox Code Playgroud) 为什么我的指针的 static_cast 失败?
int iDog = 456;
int *piDog = &iDog;
long *plDog = static_cast<long*>(piDog); // invalid type conversion
long lDog = static_cast<long>(iDog); // ok
long* plDog = (long*)(piDog); // this is OK too... very weird!! (Dynamic cast... and we aren't allowed to use this one in our coding standards)
Run Code Online (Sandbox Code Playgroud)
这个参考表明它应该没问题:https : //en.cppreference.com/w/cpp/language/static_cast
Visual Studio C++ 的问题?
我尝试用左右范围为基础的for循环中,如果您使用范围为基础,通过矢量循环来运行到超出范围的错误有没有办法避免这种错误,如果您使用的是基于范围的for循环
int main()
{
vector<int> num{ 1,2,3,4,5 };
for (auto i : num)
{
cout << num[i] << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
它显示了这个错误
c++ for-loop outofrangeexception visual-c++ range-based-loop
我是 C++ 的完全菜鸟,我遇到的第一个问题如下:
没有运算符 >> 匹配这些操作数
#include "pch.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "hello world!";
cin >> "hello world!";
}
Run Code Online (Sandbox Code Playgroud) c++ ×10
visual-c++ ×10
64-bit ×1
architecture ×1
c++11 ×1
clang ×1
for-loop ×1
g++ ×1
gcc ×1
x86 ×1