- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有以下问题:
我的代码适用于 Visual C++ 2010,但是当我在 Linux 上编译它时,它被编译了,但是有些东西不起作用:
这是我的 Vector
输入 operator>>
:
istream& operator>>(istream& in,Vector& x)
{
char a;
in.sync();
a=in.get(); //gets the '['
for(int i=0;i<x._n;i++)
{
in>>x._vector[i];
if ((i+1)!=x._n)
a=in.get(); //gets the ','
}
in>>a; //gets the ']'
return in;
}
_vector
指向一个 Complex
数组,Complex
的 operator>>
工作正常。
输入应该是这样的:
[2+3i,9i,1]
当我在 visual c++ 2010 上运行这段代码时,它运行正常,看起来像这样:
cin>>v; // [1+1i,2]
cin>>u; // [10,5i]
cout<<v<<endl; //prints: [1+i,2]
cout<<u<<endl; //prints: [10,5i]
当我在 Linux 上运行相同的代码时,在第一个数组 [1+1i,2]
之后程序结束:
[1+1i,2] //this is the input
[6.105e-317+6.105e-317i,6.105e-317+6.105e-317i]
[6.105e-317+6.105e-317i,6.105e-317+6.105e-317i]
现在我什至不能写另一个 Vector
顺便说一句:这是我的 Vector.h
#ifndef _VECTOR_
#define _VECTOR_
#include <iostream>
using namespace std;
#include "Complex.h"
class Vector
{
private:
int _n;
Complex *_vector; //points on the array of the complex numbers
public:
Vector(int n); // "Vector" - constructor of Vector with n instants
Vector(const Vector& x); // "Vector" - copy constructor of Vector with n instants
~Vector(); // "~Vector" - destructor of Vector
const Vector& operator=(const Vector& x); // "operator=" - operates "=" for Vector
Complex& operator[](const int index); // "operator[]" - choose an instant by his index in the _vector
const Vector operator+(const Vector& x) const; // "operator+" - operates "+" between two vectors
const Vector operator-(const Vector& x) const; // "operator-" - operates "-" between two vectors
const Vector operator*(double scalar) const; // "operator*" - multiplate all of the instants of the vector by the scalar
friend const Vector operator*(double scalar,const Vector& x); // "operator*" - multiplate all of the instants of the vector by the scalar
const Complex operator*(const Vector& x) const; // "operator*" - operates "*" between two vectors
const Vector& operator+=(const Vector& x); // "operator+=" - operates "+=" for the instant
const Vector& operator-=(const Vector& x); // "operator-=" - operates "-=" for the instant
friend ostream& operator<<(ostream& out,const Vector& x); // "operator<<" - prints the vector
friend istream& operator>>(istream& in,Vector& x); // "operator<<" - gets the vector
const double operator!() const; // "operator!" - returns the the instant in the definite value of the vactor that his definite value is the highest (in the Vector)
};
#endif
这里是我定义 Vector 构造函数的地方: vector .cpp
#include <iostream>
using namespace std;
#include <math.h>
#include "Complex.h"
#include "Vector.h"
// "Vector" - constructor of Vector with n instants
Vector::Vector(int n)
{
_vector=new Complex[n]; //new vector (array) of complex classes
_n=n;
}
谁能帮帮我?
最佳答案
我假设问题出在您调用 in.sync()
的电话中.
这会刷新输入缓冲区,即它会丢弃当前在 istream 缓冲区中的任何数据。究竟放入缓冲区的内容取决于 a) 你的平台和 b) 你在调用 operator>>
之前做了什么.
至于b),这就是为什么调用sync
是错误的原因来自 operator>>
,但那是“你的问题”。
至于 a),您应该知道,在 istream 获得发言权之前,UNIX 系统会在操作系统级别为控制台文本输入做行缓冲。您要刷新的数据可能在操作系统缓冲区中,而不是在 istream 的缓冲区中。
如果你只想跳过空格,你应该使用in >> std::ws;
关于c++ - operator>> 适用于 Visual C++ 2010 但不适用于 Linux 上的 G++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8621784/
我在我的 Xcode 项目目录中输入了以下内容: keytool -genkey -v -keystore release.keystore -alias mykey -keyalg RSA \
假设我有一个像这样的 DataFrame(或 Series): Value 0 0.5 1 0.8 2 -0.2 3 None 4 None 5 None
我正在对一个 Pandas 系列进行相对繁重的应用。有什么方法可以返回一些打印反馈,说明每次调用函数时在函数内部进行打印还有多远? 最佳答案 您可以使用跟踪器包装您的函数。以下两个示例,一个基于完成的
我有一个 DataFrame,其中一列包含列表作为单元格内容,如下所示: import pandas as pd df = pd.DataFrame({ 'col_lists': [[1, 2
我想使用 Pandas df.apply 但仅限于某些行 作为一个例子,我想做这样的事情,但我的实际问题有点复杂: import pandas as pd import math z = pd.Dat
我有以下 Pandas 数据框 id dist ds 0 0 0 0 5 1 0 0 7 2 0 0
这发生在我尝试使用 Gradle 构建时。由于字符串是对象,因此似乎没有理由发生此错误: No signature of method: java.util.HashMap.getOrDefault(
您好,有人可以解释为什么在 remaining() 函数中的 Backbone 示例应用程序 ( http://backbonejs.org/examples/todos/index.html ) 中
我有两个域类:用户 class User { String username String password String email Date dateCreated
问题陈述: 一个 pandas dataframe 列系列,same_group 需要根据两个现有列 row 和 col 的值从 bool 值创建。如果两个值在字典 memberships 中具有相似
apporable 报告以下错误: error: unknown type name 'MKMapItem'; did you mean 'MKMapView'? MKMapItem* destina
我有一个带有地址列的大型 DataFrame: data addr 0 0.617964 IN,Krishnagiri,635115 1 0.635428 IN,Chennai
我有一个列表list,里面有这样的项目 ElementA: Number=1, Version=1 ElementB: Number=1, Version=2 ElementC: Number=1,
我正在编译我的源代码,它只是在没有运行应用程序的情况下终止。这是我得到的日志: Build/android-armeabi-debug/com.app4u.portaldorugby/PortalDo
我正在尝试根据另一个单元格的值更改单元格值(颜色“红色”或“绿色”)。我运行以下命令: df.loc[0, 'Colour'] = df.loc[0, 'Count'].apply(lambda x:
我想弄清楚如何使用 StateT结合两个 State基于对我的 Scalaz state monad examples 的评论的状态转换器回答。 看来我已经很接近了,但是在尝试申请 sequence
如果我已经为它绑定(bind)了集合,我该如何添加 RibbonLibrary 默认的快速访问项容器。当我从 UI 添加快速访问工具项时,它会抛出 Operation is not valid whi
在我学习期间Typoclassopedia我遇到了这个证明,但我不确定我的证明是否正确。问题是: One might imagine a variant of the interchange law
我是一名优秀的程序员,十分优秀!